[Python-ideas] An alternate approach to async IO

Richard Oudkerk shibturn at gmail.com
Wed Nov 28 14:00:35 CET 2012

On 28/11/2012 12:07pm, Sturla Molden wrote:
> That way the main "Python thread" would never loose
> the GIL to a thread from the IOCP. Instead it would shortly
> busy-wait while a completed task is inserted into the queue.
> Thus synchronization by the GIL is replaced by a spinlock
> protecting a queue (or an interlocked list on recent Windows versions).

How do you know the busy wait will be short?

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.)

I very much doubt that GetQueuedCompletionStatus*() consumes enough cpu 
time for it to be worth running in a thread pool (particularly if it 
forces busy waiting on you).


More information about the Python-ideas mailing list