[openstack-dev] Asynchrounous programming: replace eventlet with asyncio

Zane Bitter zbitter at redhat.com
Fri Feb 7 02:49:30 UTC 2014


On 04/02/14 13:53, Kevin Conway wrote:
> On 2/4/14 12:07 PM, "victor stinner"<victor.stinner at enovance.com>  wrote:
>> >The purpose of replacing eventlet with asyncio is to get a well defined
>> >control flow, no more surprising task switching at random points.
>
> I disagree with this. Eventlet and gevent yield the execution context
> anytime an IO call is made or the 'sleep()' function is called explicitly.
> The order in which greenthreads grain execution context is deterministic
> even if not entirely obvious. There is no context switching at random.

This is technically correct of course, but in reality there's no way to 
know whether a particular piece of code is safe from context switches 
unless you have the entire codebase of the program and all of its 
libraries in your head at the same time. So no, it's not *random*, but 
it might as well be. And it's certainly not explicit in the way that 
asyncio is explicit; it's very much implicit in other operations.

> What's more is it shouldn't matter when the context switch happens. When
> writing green threaded code you just pretend you have real threads and
> understand that things happen in an order other than A => B => C.

If you like pretending you have real threads, you could just use Python 
threads. Greenthreads exist because people don't want to deal with 
actual pretend threads.

> One of the great benefits of using a green thread abstraction, like
> eventlet or gevent, is that it lets you write normal Python code and slap
> your concurrency management over the top.

Right, it lets you do that and neglects to mention that it doesn't 
actually work.

The whole premise of eventlet is that it allows you to write your code 
without thinking about thread safety, except that you *do* still have to 
think about thread safety. So the whole reason for its existence is to 
write cheques that it can't cash. It's conceptually unsound at the most 
fundamental level.

I'm not suggesting for a second that it would be an easy change - I'm 
not even sure it would be a good change - but let's not kid ourselves 
that everything is fine here in happy-land and there's nothing to discuss.

cheers,
Zane.



More information about the OpenStack-dev mailing list