[Python-Dev] async/await in Python; v2 (original) (raw)

Andrew Svetlov andrew.svetlov at gmail.com
Wed Apr 22 21:37:16 CEST 2015


On Wed, Apr 22, 2015 at 10:24 PM, Yury Selivanov <yselivanov.ml at gmail.com> wrote:

On 2015-04-22 2:53 PM, Andrew Svetlov wrote:

On Wed, Apr 22, 2015 at 9:45 PM, Yury Selivanov <yselivanov.ml at gmail.com> wrote: [...]

If we forbid to call async def from regualr code how asyncio should work? I'd like to push async def everywhere in asyncio API where asyncio.coroutine required. You'll have to use a wrapper that will do the following: async def foo(): return 'spam' @asyncio.coroutine def bar(): what = yield from foo.await(foo, *args, **kwargs) # OR: what = yield from awaitcall(foo, *args, **kwargs) If I cannot directly use yield from f() with async def f(): then almost every yield from inside asyncio library should be wrapped in awaitcall(). Every third-party asyncio-based library should do the same. Also I expect a performance degradation on awaitcall() calls.

I think there is another way... instead of pushing GETITER ... YIELDFROM opcodes, we'll need to replace GETITER with another one: GETITERSPECIAL ... YIELDFROM

Where "GETITERSPECIAL (obj)" (just a working name) would check that if the current code object has COCOROUTINE and the object that you will yield-from has it as well, it would push to the stack the result of (obj.await()) GET_ITER_SPECIAL sounds better than wrapper for coro.__await__() call.

Yury

-- Thanks, Andrew Svetlov



More information about the Python-Dev mailing list