[Python-ideas] Async API

Kristján Valur Jónsson kristjan at ccpgames.com
Fri Oct 26 14:03:32 CEST 2012


> -----Original Message-----
> From: Python-ideas [mailto:python-ideas-
> bounces+kristjan=ccpgames.com at python.org] On Behalf Of Sam Rushing
> Sent: 23. október 2012 23:01
> To: Yury Selivanov
> Cc: python-ideas at python.org
> Subject: Re: [Python-ideas] Async API
> 
> In shrapnel it is simply:
> 
>     coro.with_timeout (<seconds>, <fun>, *args, **kwargs)
> 
> Timeouts are caught thus:
> 
>    try:
>       coro.with_timeout (...)
>    except coro.TimeoutError:
>       ...

Hi Sam ( I rember our talk about Shrapnel here at CCP some years back)
, others:

Jumping in here with some random stuff, in case anyone cares:

A few years ago, I started trying to create a standard library for stackless python.
we use it internally at ccp and it is open source, at https://bitbucket.org/krisvale/stacklesslib

What it provides is
1) some utility classes for stackless (context managers mostly) but also synchronization primitives.
2) a basic "main" functionality:  A main loop and an event scheduler
3) a set of replacement modules for threading/socket, etc
4) Monkeypatching tools, to monkeypatch in the replacements, and even run monkeypatched scripts.

On the basis of the event scheduler, I also implemented timeout for socket.receive() functions.  These used to allow e.g. timeouts for locking operations

Timeouts are indeed implemented as exceptions raised.  There are some minor race issues to think about but that's it.


Notice the need for a stacklesslib.main module.  The issue I have found with this sort of event driven model, is that composability suffers when everyone has their own idea about what a "main" loop should be.  In threaded programming, the OS provides the main loop and the event scheduler.  For something like Python, a whole application has to agree on what the main loop is, and how to schedule future events.  Hopefully this discussion is an attempt to settle that in a standard manner.

Cheers,

Kristján
p.s. stacklesslib is in a state of protracted and procrastinated development.  I promised that I would fix it up at last pycon.  Mostly I'm working on restructuring and making the main loop work more "out of the box."




More information about the Python-ideas mailing list