[Python-ideas] Async API: some code to review
Yury Selivanov
yselivanov.ml at gmail.com
Mon Oct 29 17:47:50 CET 2012
On 2012-10-29, at 12:07 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> To invoke a primitive I/O operation, you call the current task's
>> block() method and then immediately yield (similar to Greg Ewing's
>> approach). There are helpers block_r() and block_w() that arrange for
>> a task to block until a file descriptor is ready for reading/writing.
>> Examples of their use are in sockets.py.
>
> That's weird and kindof ugly IMHO. Why would you write:
>
> scheduling.block_w(self.sock.fileno())
> yield
>
> instead of say:
>
> yield scheduling.block_w(self.sock.fileno())
>
> ?
I, personally, like and use the second approach. But I believe the
main incentive for Guido & Greg to use 'yields' like that is to make
one thing *very* clear: always use 'yield from' to call something.
'yield' statement is just an explicit context switch point, and it
should be used only for that purpose and only when you write a
low-level APIs.
-
Yury
More information about the Python-ideas
mailing list