[Python-ideas] An alternate approach to async IO

Richard Oudkerk shibturn at gmail.com
Fri Nov 30 16:20:28 CET 2012

On 28/11/2012 11:04pm, Trent Nelson wrote:
>      Right.  The funny thing about that is it's only available in Vista
>      onwards.  And if you're on Vista onwards, the new thread pool APIs
>      available, which negate the need to call GetQueuedCompletionStatus*
>      at all.
>          Trent.

Completion ports are just thread safe queues equivalent to queue.Queue 
in Python: PostQueuedCompletionStatus() corresponds to Queue.put() and 
GetQueuedCompletionStatus() corresponds to Queue.get().  They are not 
specific to IO and can be used for general message passing between threads.

I suspect that registering a file handle to a completion port is simply 
implemented (at least on XP) by using BindIoCompletionCallback() to 
register a callback which calls PostQueuedCompletionStatus() whenever a 
operation completes on that handle.

You seem to be proposing to do *exactly the same thing*, but using a 
different queue implementation (and using a Vista only equivalent of 

I also suspect that if you try to implement a thread safe queue which 
does not busy wait, then you will end up having to add synchronization 
which makes using a interlocked list unnecessary and slower than using a 
normal list.  Will it really superior to the operating systems builtin 
queue implementation?


More information about the Python-ideas mailing list