[Python-ideas] async: feedback on EventLoop API

Geert Jansen geertj at gmail.com
Tue Dec 18 08:26:00 CET 2012


On Tue, Dec 18, 2012 at 1:00 AM, Guido van Rossum <guido at python.org> wrote:
> On Mon, Dec 17, 2012 at 2:11 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> On Tue, 18 Dec 2012 11:00:35 +1300
>> Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>>> Guido van Rossum wrote:
>>> > (*) Most event loops I've seen use e.g. 30 seconds or 1 hour as
>>> > infinity, with the idea that if somehow a race condition added
>>> > something to the ready queue just as we went to sleep, and there's no
>>> > I/O at all, the system will recover eventually.
>>>
>>> I don't see how such a race condition can occur in a
>>> cooperative multitasking system. There are no true
>>> interrupts that can cause something to happen when
>>> you're not expecting it. So I'd say let infinity
>>> really mean infinity.
>>
>> Most event loops out there allow you to schedule callbacks from other
>> (preemptive, OS-level) threads.
>
> That's what call_soon_threadsafe() is for. But bugs happen (in either
> user code or library code). And yes, call_soon_threadsafe() will use a
> self-pipe on UNIX. (I hope someone else will write the Windows main
> loop.)

I needed a self-pipe on Windows before. See below. With this, the
select() based loop might work unmodified on Windows.

https://gist.github.com/4325783

Of course it wouldn't be as efficient as an IOCP based loop.

Regards,
Geert



More information about the Python-ideas mailing list