[Core] Remove asyncio.ensure_future call in run_async_func_in_event_loop - #32932
Conversation
Signed-off-by: Jiajun Yao <jeromeyjj@gmail.com>
| coroutine = func(*args, **kwargs) | ||
| if threading.get_ident() == async_thread.ident: | ||
| future = asyncio.ensure_future(coroutine, eventloop) | ||
| future = asyncio.ensure_future(coroutine, loop=eventloop) |
There was a problem hiding this comment.
Hmm i think we should unify the code path here, especially run_coroutine_threadsafe can perform the check for us.
I believe this is triggered when the serde code gets called while we are in async thread, and the serde functions themselves involves calling async funcs. this is probably due to the fact during await object_ref the core worker as of 3 years ago will recursively call into this function so we need to handle this case.
nevertheless, this is definitely legacy code and safe to unify
rkooo567
left a comment
There was a problem hiding this comment.
It's surprising this wasn't caught from testing? Can you add proper unit tests?
Unfortunately I was not able to get a reproduce. After talking to Simon, we think the code can be safely deleted. |
…oop(ray-project#32932) asyncio.run_coroutine_threadsafe can work regardless whether the calling thread is the same as the event loop thread or not. The original asyncio.ensure_future call is also wrong: asyncio.ensure_future has the signature asyncio.ensure_future(obj, *, loop=None) so loop has to be provided as a keyword argument instead of positional argument. Signed-off-by: Jiajun Yao <jeromeyjj@gmail.com> Signed-off-by: Jack He <jackhe2345@gmail.com>
…oop(ray-project#32932) asyncio.run_coroutine_threadsafe can work regardless whether the calling thread is the same as the event loop thread or not. The original asyncio.ensure_future call is also wrong: asyncio.ensure_future has the signature asyncio.ensure_future(obj, *, loop=None) so loop has to be provided as a keyword argument instead of positional argument. Signed-off-by: Jiajun Yao <jeromeyjj@gmail.com> Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
…oop(ray-project#32932) asyncio.run_coroutine_threadsafe can work regardless whether the calling thread is the same as the event loop thread or not. The original asyncio.ensure_future call is also wrong: asyncio.ensure_future has the signature asyncio.ensure_future(obj, *, loop=None) so loop has to be provided as a keyword argument instead of positional argument. Signed-off-by: Jiajun Yao <jeromeyjj@gmail.com>
…oop(ray-project#32932) asyncio.run_coroutine_threadsafe can work regardless whether the calling thread is the same as the event loop thread or not. The original asyncio.ensure_future call is also wrong: asyncio.ensure_future has the signature asyncio.ensure_future(obj, *, loop=None) so loop has to be provided as a keyword argument instead of positional argument. Signed-off-by: Jiajun Yao <jeromeyjj@gmail.com> Signed-off-by: elliottower <elliot@elliottower.com>
…oop(ray-project#32932) asyncio.run_coroutine_threadsafe can work regardless whether the calling thread is the same as the event loop thread or not. The original asyncio.ensure_future call is also wrong: asyncio.ensure_future has the signature asyncio.ensure_future(obj, *, loop=None) so loop has to be provided as a keyword argument instead of positional argument. Signed-off-by: Jiajun Yao <jeromeyjj@gmail.com> Signed-off-by: Jack He <jackhe2345@gmail.com>
Why are these changes needed?
asyncio.run_coroutine_threadsafe can work regardless whether the calling thread is the same as the event loop thread or not.
The original asyncio.ensure_future call is also wrong: asyncio.ensure_future has the signature
asyncio.ensure_future(obj, *, loop=None)so loop has to be provided as a keyward argument instead of positional argument.I think this is the cause of https://discuss.ray.io/t/typeerror-ensure-future-takes-1-positional-argument-but-2-were-given/9453
Related issue number
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.