[Python-Dev] async/await in Python; v2

Paul Sokolovsky pmiscml at gmail.com
Thu Apr 23 00:21:54 CEST 2015


Hello,

On Wed, 22 Apr 2015 13:31:18 -0700
Guido van Rossum <guido at python.org> wrote:

> On Wed, Apr 22, 2015 at 1:10 PM, Andrew Svetlov
> <andrew.svetlov at gmail.com> wrote:
> 
> > On Wed, Apr 22, 2015 at 10:44 PM, PJ Eby <pje at telecommunity.com>
> > wrote:
> > > On Tue, Apr 21, 2015 at 1:26 PM, Yury Selivanov
> > > <yselivanov.ml at gmail.com>
> > wrote:
> > >> It is an error to pass a regular context manager without
> > >> ``__aenter__`` and ``__aexit__`` methods to ``async with``.  It
> > >> is a ``SyntaxError`` to use ``async with`` outside of a
> > >> coroutine.
> > >
> > > I find this a little weird.  Why not just have `with` and `for`
> > > inside a coroutine dynamically check the iterator or context
> > > manager, and either behave sync or async accordingly?  Why must
> > > there be a *syntactic* difference?
> >
> > IIRC Guido always like to have different syntax for calling regular
> > functions and coroutines.
> > That's why we need explicit syntax for asynchronous context managers
> > and iterators.
> >
> 
> To clarify: the philosophy behind asyncio coroutines is that you
> should be able to tell statically where a task may be suspended
> simply by looking for `yield from`. This means that *no* implicit
> suspend points may exist, and it rules out gevent, stackless and
> similar microthreading frameworks.

I always wanted to ask - does that mean that Python could have
symmetric coroutines (in a sense that it would be Pythonic feature), as
long as the call syntax is different from a function call?

E.g.:

sym def coro1(val):
    while True:
        val = coro2.corocall(val)

sym def coro2(val):
    while True:
        val = coro1.corocall(val)

coro1.call(1)


-- 
Best regards,
 Paul                          mailto:pmiscml at gmail.com


More information about the Python-Dev mailing list