def submit(self, func, *args, **kwargs): """Register a function and its arguments for asynchronous execution. ``*args`` and ``**kwargs`` must be serializable in JSON. """ try: args = [executor.get_actual_value(arg) for arg in args] kwargs = {key: executor.get_actual_value(val) for key, val in kwargs.iteritems()} except exceptions.ExecutionBlocked: return futures.Future() try: if isinstance(func, Activity): task = self.make_activity_task(func, *args, **kwargs) elif issubclass(func, Workflow): task = self.make_workflow_task(func, *args, **kwargs) else: raise TypeError except TypeError: raise TypeError('invalid type {} for {}'.format( type(func), func)) return self.resume(task, *args, **kwargs)
def submit(self, func, *args, **kwargs): """Register a function and its arguments for asynchronous execution. ``*args`` and ``**kwargs`` must be serializable in JSON. """ errors = [] arguments = [] keyword_arguments = {} result = None try: for arg in args: if isinstance(arg, futures.Future) and arg.failed: exc = arg._exception if isinstance(exc, exceptions.MultipleExceptions): errors.extend(exc.exceptions) else: errors.append(exc) else: arguments.append(executor.get_actual_value(arg)) for key, val in kwargs.iteritems(): if isinstance(val, futures.Future) and val.failed: exc = val._exception if isinstance(exc, exceptions.MultipleExceptions): errors.extend(exc.exceptions) else: errors.append(val._exception) else: keyword_arguments[key] = executor.get_actual_value(val) except exceptions.ExecutionBlocked: result = futures.Future() finally: if errors: result = futures.Future() result._state = futures.FINISHED result._exception = exceptions.MultipleExceptions( 'futures failed', errors, ) if result is not None: return result try: if isinstance(func, Activity): make_task = self.make_activity_task elif issubclass(func, Workflow): make_task = self.make_workflow_task else: raise TypeError task = make_task(func, *arguments, **keyword_arguments) except TypeError: raise TypeError('invalid type {} for {}'.format( type(func), func)) return self.resume(task, *arguments, **keyword_arguments)
def map(self, callable, iterable): """Submit *callable* with each of the items in ``*iterables``. All items in ``*iterables`` must be serializable in JSON. """ iterable = executor.get_actual_value(iterable) return super(Executor, self).map(callable, iterable)
def submit(self, func, *args, **kwargs): logger.info('executing task {}(args={}, kwargs={})'.format( func, args, kwargs)) args = [executor.get_actual_value(arg) for arg in args] kwargs = {key: executor.get_actual_value(val) for key, val in kwargs.iteritems()} future = futures.Future() try: future._result = func._callable(*args, **kwargs) except Exception as err: future._exception = err raise finally: future._state = futures.FINISHED return future
def submit(self, func, *args, **kwargs): logger.info('executing task {}(args={}, kwargs={})'.format( func, args, kwargs)) args = [executor.get_actual_value(arg) for arg in args] kwargs = { key: executor.get_actual_value(val) for key, val in kwargs.iteritems() } future = futures.Future() try: future._result = func._callable(*args, **kwargs) except Exception as err: future._exception = err raise finally: future._state = futures.FINISHED return future
def starmap(self, callable, iterable): iterable = executor.get_actual_value(iterable) return super(Executor, self).starmap(callable, iterable)