No, we can't, because the async/await are interpreted by the compiler, while the presence of an event loop is a condition of the runtime.
On Tue, May 5, 2015 at 2:03 PM, Eric V. Smith email@example.com wrote:
On 5/5/2015 2:48 PM, Guido van Rossum wrote:
If we're going through all of the effort to elevate await and async def to syntax, then can't the interpreter also be aware if it's running an event loop? Then, if we are running an event loop, await becomes "yield from", using the event loop. But if we're not running an event loop, then await becomes a blocking wait, using some version of run_until_complete, whether really from asyncio or baked into the interpreter.
This way, I can write my library code as being async, but it's still usable from non-async code (although it would need to be called with await, of course).
I'll admit I haven't thought this all the way through, and I'm still reading through PEP 492. But if I can write my async code as if it were blocking using await, why can't it really be blocking, too?
Python-ideas mailing list Pythonfirstname.lastname@example.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido)