[Python-ideas] An alternate approach to async IO

Trent Nelson trent at snakebite.org
Wed Nov 28 20:23:47 CET 2012


On Wed, Nov 28, 2012 at 11:11:42AM -0800, Richard Oudkerk wrote:
> On 28/11/2012 6:59pm, Sturla Molden wrote:
> >
> >> You are assuming that GetQueuedCompletionStatus*() will never block
> >> because of lack of work.
> >
> > GetQueuedCompletionStatusEx takes a time-out argument, it can be zero.
> >
> > Sturla
> 
> According to your (or Trent's) idea the main thread busy waits until the 
> interlocked list is non-empty.  If there is no work to do then the 
> interlocked list is empty and the main thread will busy wait till there 
> is work to do, which might be for a long time.

    Oooer, that's definitely not what I had in mind.  This is how I
    envisioned it working (think of events() as similar to poll()):

        with aio.events() as events:
            for event in events:
                # process event
                ...

    That aio.events() call would result in an InterlockedSListFlush,
    returning the entire list of available events.  It then does the
    conversion into a CPython event type, bundles everything into a
    list, then returns.

    (In reality, there'd be a bit more glue to handle an empty list
     a bit more gracefully, and probably a timeout to aio.events().
     Nothing should involve a spinlock though.)

        Trent.



More information about the Python-ideas mailing list