[Python-ideas] Async API: some code to review
Paul Colomiets
paul at colomiets.name
Tue Oct 30 22:45:46 CET 2012
Hi Richard,
On Mon, Oct 29, 2012 at 3:13 PM, Richard Oudkerk <shibturn at gmail.com> wrote:
> On 28/10/2012 11:52pm, Guido van Rossum wrote:
>>
>> I'm most interested in feedback on the design of polling.py and
>> scheduling.py, and to a lesser extent on the design of sockets.py;
>> main.py is just an example of how this style works out in practice.
>
>
> What happens if two tasks try to do a read op (or two tasks try to do a
> write op) on the same file descriptor? It looks like the second one to do
> scheduling.block_r(fd) will cause the first task to be forgotten, causing
> the first task to block forever.
>
> Shouldn't there be a list of pending readers and a list of pending writers
> for each fd?
>
There is another approach to handle this. You create a dedicated
coroutine which does writing (or reading). And if other coroutine
needs to write, it puts data into a queue (or channel), and wait until
writer coroutine picks it up. This way you don't care about atomicity
of writes, and a lot of other things.
This approach is similar to what Greg Ewing proposed for handling
accept() recently.
--
Paul
More information about the Python-ideas
mailing list