| Store | Cart

Re: [Python-Dev] Importance of "async" keyword

From: Ron Adam <ron3...@gmail.com>
Fri, 26 Jun 2015 14:06:04 -0400

On 06/26/2015 10:31 AM, Chris Angelico wrote:
> Apologies if this is a really REALLY dumb question, but... How hard> would it be to then dispense with the await keyword, and simply> _always_  behave that way? Something like:>> def data_from_socket():>      # Other tasks may run while we wait for data>      # The socket.read() function has yield points in it>      data = socket.read(1024, 1)>      return transmogrify(data)>> def respond_to_socket():>      while True:>          data = data_from_socket()>          # We can pretend that socket writes happen instantly,>          # but if ever we can't write, it'll let other tasks wait while>          # we're blocked on it.>          socket.write("Got it, next please!")>> Do these functions really need to be aware that there are yield points> in what they're calling?

I think "yield points" is a concept that needs to be spelled out a bit 
clearer in the PEP 492.

It seems that those points are defined by other means outside of a function 
defined with "async def".  From the PEP...

    * It is a SyntaxError to have yield or yield from expressions
      in an async function.

So somewhere in an async function, it needs to "await something" with a 
yield in it that isn't an async function.

This seems to be a bit counter intuitive to me.  Or am I missing something?

Regards,
    Ron




















_______________________________________________
Python-Dev mailing list
Pyth...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/python-dev-ml%40activestate.com

Recent Messages in this Thread
Sven R. Kunze Jun 24, 2015 06:14 pm
Yury Selivanov Jun 24, 2015 08:16 pm
Sven R. Kunze Jun 24, 2015 09:21 pm
Steven DAprano Jun 25, 2015 02:16 am
Sven R. Kunze Jun 25, 2015 03:55 pm
Andrew Svetlov Jun 25, 2015 07:11 pm
Nick Coghlan Jun 26, 2015 10:46 am
Sven R. Kunze Jun 26, 2015 01:48 pm
Ethan Furman Jun 26, 2015 02:20 pm
Chris Angelico Jun 26, 2015 02:31 pm
Paul Sokolovsky Jun 26, 2015 02:51 pm
Chris Angelico Jun 26, 2015 03:10 pm
R. David Murray Jun 26, 2015 04:07 pm
Chris Angelico Jun 26, 2015 04:20 pm
Yury Selivanov Jun 26, 2015 03:48 pm
Nick Coghlan Jun 26, 2015 05:29 pm
Ron Adam Jun 26, 2015 06:06 pm
Nick Coghlan Jun 27, 2015 01:42 am
Steve Dower Jun 26, 2015 03:47 pm
Ethan Furman Jun 26, 2015 05:40 pm
Yury Selivanov Jun 26, 2015 06:30 pm
Sven R. Kunze Jun 30, 2015 07:39 pm
Greg Ewing Jul 01, 2015 10:02 pm
Sven R. Kunze Jul 02, 2015 08:55 pm
Nick Coghlan Jul 03, 2015 09:40 am
Sven R. Kunze Jul 05, 2015 09:50 pm
Chris Angelico Jul 06, 2015 12:27 am
Nick Coghlan Jul 06, 2015 01:41 am
Sven R. Kunze Jul 06, 2015 08:08 pm
Nick Coghlan Jul 07, 2015 12:40 pm
Steve Dower Jul 06, 2015 02:03 am
Steve Dower Jun 26, 2015 07:03 pm
Nick Coghlan Jun 26, 2015 05:05 pm
Greg Ewing Jun 25, 2015 10:02 pm
Nick Coghlan Jun 26, 2015 10:52 am
Steven DAprano Jun 26, 2015 02:22 am
Messages in this thread