diff --git a/beat/backend/python/algorithm.py b/beat/backend/python/algorithm.py index af0fc272cf8480e3c0cfbb5a7b61fb2ffed96d2c..d5584dbd68300ae492585295f064914e17ef1c22 100644 --- a/beat/backend/python/algorithm.py +++ b/beat/backend/python/algorithm.py @@ -42,8 +42,6 @@ import six import numpy import simplejson -from inspect import signature - from . import dataformat from . import library from . import loader @@ -257,15 +255,13 @@ class Runner(object): elif self.algorithm.type == Algorithm.AUTONOMOUS: run_args = [self.obj, 'process', self.exc, data_loaders, outputs_to_use] - sig = signature(self.obj.process) - params = sig.parameters - + has_loop_arg = utils.has_argument(self.obj.process, 'loop_channel') if loop_channel is not None: - if 'loop_channel' in params: + if has_loop_arg: run_args.append(loop_channel) else: raise exc("Algorithm '%s' is not a valid loop enabled algorithm" % self.name) - elif 'loop_channel' in params: + elif has_loop_arg: raise exc("Algorithm '%s' is a loop enabled algorithm but no loop_channel given" % self.name) return loader.run(*run_args) diff --git a/beat/backend/python/utils.py b/beat/backend/python/utils.py index eacb837b51295afcf325f7efe57510701bbee78e..c18963b03d34eda38d187c9b07266a6cae2eb29f 100644 --- a/beat/backend/python/utils.py +++ b/beat/backend/python/utils.py @@ -360,3 +360,18 @@ class NumpyJSONEncoder(simplejson.JSONEncoder): if obj.name == 'str': return 'string' return obj.name return simplejson.JSONEncoder.default(self, obj) + + +# ---------------------------------------------------------- + + +def has_argument(method, argument): + try: + from inspect import signature + sig = signature(method) + params = sig.parameters + except ImportError: + from inspect import getargspec + params = getargspec(method).args + + return argument in params