def wrap(*args, **kwargs): q = Queue() t = Thread(target=wrapped_f, args=(q, ) + args, kwargs=kwargs) t.daemon = daemon t.start() t.result_queue = q return t
def wrap(*args, **kwargs): queue = Queue.Queue() thread = Thread(target=wrapped_function, args=(queue,)+args , kwargs=kwargs) thread.daemon=daemon thread.start() thread.result_queue=queue return thread
def wrap(*args, **kwargs): try: if kwargs.get('recursive'): return f(*args, **kwargs) except KeyError: pass q = Queue() t = Thread(target=wrapped_f, args=(q, ) + args, kwargs=kwargs) t.daemon = daemon t.start() t.result_queue = q return t
def async_func(*args, **kwargs): """ Run a function asynchronously :param args: all arguments will be passed to the target function :param kwargs: pass a Queue.Queue() object with the optional 'queue' keyword if you would like to retrieve the results after the thread has run. All other keyword arguments will be passed to the target function. :return: the created Thread object that the function is running in. """ t = Thread(target=func, args=args, kwargs=kwargs) queue = kwargs.get("queue", None) if queue is not None: t.result_queue = queue t.start() return t