[issue22239] asyncio: nested event loop
Rokas K. (rku)
report at bugs.python.org
Sat Jul 15 04:21:47 EDT 2017
Rokas K. (rku) added the comment:
I understand rationale for rejection of this issue but i beg to reconsider.
Unlike in traditional coroutines (windows fibers / setjmp|longjmp with stack switching) we can not yield from any point of execution. There must be full async-await chain preserved. This basically divides code into two islands - async and non-async. And there seems to be no way to schedule async call from non-async code and get a response. While suggestion to make custom `async def contains()` call is a valid one we can not always do that. Consider the case when we have to do some networking calls in a function that is invoked by non-async library. Naturally it would be simple non-awaited call from which we can not call a coroutine and get a response. And since it is a library calling into our code we can not easily change it. It might even be completely unsuitable change for library in question.
I see two solutions to this problem (if i am missing something please point it out):
1. Reentrant loops as suggested in this issue.
2. Allow awaited calls from non-coroutines provided execution is invoked from a coroutine somewhere up the call stack.
First one is certainly easier to implement.
----------
nosy: +Rokas K. (rku)
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22239>
_______________________________________
More information about the Python-bugs-list
mailing list