[Python-ideas] An alternate approach to async IO

Sturla Molden sturla at molden.no
Wed Nov 28 16:07:56 CET 2012


On 28.11.2012 14:00, Richard Oudkerk wrote:

> If you are worried about the cost of acquiring and releasing the GIL
> more than necessary, then why not just dequeue as many completion
> packets as possible at once. (On Vista and later
> GetQueuedCompletionStatusEx() produces an array of completion packets;
> on WinXP you can get a similar effect by calling
> GetQueuedCompletionStatus() in a loop.)

Hmm, yes, perhaps---

One could call GetQueuedCompletionStatusEx in a loop and set 
dwMilliseconds to 0 (immediate timeout), possibly with a Sleep(0) if the 
task queue was empty. (Sleep(0) releases the reminder of the time-slice, 
and so prevents spinning on GetQueuedCompletionStatusEx from burning the 
CPU.) If after a while (say 10 ms) there is still no tasks in the queue, 
we release the GIL and call GetQueuedCompletionStatusEx with a longer 
time-out than 0.

Sturla




More information about the Python-ideas mailing list