Implement async get for direct actor call (#6339)

This commit is contained in:
Simon Mo
2019-12-18 11:50:21 -08:00
committed by GitHub
parent ec4f8d5311
commit 26ec500ef9
13 changed files with 263 additions and 8 deletions
+11 -1
View File
@@ -88,9 +88,19 @@ def init():
"""
assert ray.is_initialized(), "Please call ray.init before async_api.init"
# Noop when handler is set.
if handler is not None:
return
loop = asyncio.get_event_loop()
if loop.is_running():
asyncio.ensure_future(_async_init())
assert loop._thread_id != threading.get_ident(), (
"You are using async_api inside a running event loop. "
"Please call `await _async_init()` to initialize inside "
"asynchrounous context.")
# If the loop is runing outside current thread, we actually need
# to do this to make sure the context is initialized.
asyncio.run_coroutine_threadsafe(_async_init(), loop=loop)
else:
asyncio.get_event_loop().run_until_complete(_async_init())