def create_threadpool_executed_func(original_func):
def wrapped_func(*args, **kwargs):<EOL><INDENT>try:<EOL><INDENT>result = original_func(*args, **kwargs)<EOL>return True, result<EOL><DEDENT>except:<EOL><INDENT>return False, sys.exc_info()<EOL><DEDENT><DEDENT>def new_func(*args, **kwargs):<EOL><INDENT>status, result = gevent.get_hub().threadpool.apply(wrapped_func, args, kwargs)<EOL>if status:<EOL><INDENT>return result<EOL><DEDENT>else:<EOL><INDENT>six.reraise(*result)<EOL><DEDENT><DEDENT>new_func.__name__ = original_func.__name__<EOL>new_func.__doc__ = "<STR_LIT>" + ("<STR_LIT:U+0020>" + original_func.__doc__ if original_func.__doc__ is not None else "<STR_LIT>")<EOL>return new_func<EOL>
Returns a function wrapper that defers function calls execute inside gevent's threadpool but keeps any exception
or backtrace in the caller's context.
:param original_func: function to wrap
:returns: wrapper function