Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def make_coro():
coro = gen.maybe_future(func(*args, **kwargs))
if timeout is None:
return coro
else:
return gen.with_timeout(timedelta(seconds=timeout), coro)
if not loop._running:
try:
return loop.run_sync(make_coro)
except RuntimeError: # loop already running
pass
e = threading.Event()
main_tid = get_thread_identity()
result = [None]
error = [False]
@gen.coroutine
def f():
try:
if main_tid == get_thread_identity():
raise RuntimeError("sync() called from thread of running loop")
yield gen.moment
thread_state.asynchronous = True
result[0] = yield make_coro()
except Exception as exc:
logger.exception(exc)
error[0] = sys.exc_info()
finally:
thread_state.asynchronous = False
def f():
try:
if main_tid == get_thread_identity():
raise RuntimeError("sync() called from thread of running loop")
yield gen.moment
thread_state.asynchronous = True
result[0] = yield make_coro()
except Exception as exc:
logger.exception(exc)
error[0] = sys.exc_info()
finally:
thread_state.asynchronous = False
e.set()