[Python-ideas] async objects

Stephen J. Turnbull turnbull.stephen.fw at u.tsukuba.ac.jp
Tue Oct 4 03:50:20 EDT 2016


Nick Coghlan writes:

 > What's not well-defined are the interfaces for calling into
 > asynchronous code from synchronous code.

I don't understand the relevance to the content of the thread.

As I understand the main point, Sven and Rene don't believe that [the
kind of] async code [they want to write] should need any keywords;
just start the event loop and invoke functions, and that somehow
automatically DTRTs.  (I.e., AFAICS the intent is to unify generators
and coroutines despite the insistence of Those Who Have Actually
Implemented Stuff that generator != coroutine.)

N.B. As I understand it, although Rene uses the async keyword when
invoking the constructor, this could be just as well done with a
factory function since he speaks of "wrapping" the object.  And his
example is in your "just call it" category: nonblocking synchronous
code.  That doesn't help me understand what he's really trying to do.

His PyWorks project is documented as implementing the "actor" model,
but async is more general than that AFAICS, and on the other hand I
can't see how you can guarantee that a Python function won't modify
global state.  So OK, I can see that a performant implementation of
the actor pattern (don't we have this in multiprocessing somewhere?) 
with a nice API (that's harder :-) and documented restrictions on what
you can do in there might be a candidate for stdlib, but I don't see
how it's related to the "async(io)" series of PEPs, which are
specifically about interleaving arbitrary amounts of suspension in a
Python program (which might manipulate global state, but we want to do
it in a way such that we know that code between suspension points
executes "atomically" from the point of view of other coroutines).

Anthony also objects to the keywords, ie, that he'll need to pepper
his "dual-purpose" code with "async" and "await".  Again, AFAICS that
implies that he doesn't see a need to distinguish async from lazy
(coroutine from generator), since AFAICS you'd break the world if you
changed the semantics of "def foo" to "async def foo".  So if you're
going to write async/await-style code, you're going to have to swallow
the keywords.

Am I just missing something?



More information about the Python-ideas mailing list