Is it safe to mix green threads and native threads in the same python process?

First, is it safe to mix green threads like eventlet or gevent with native python threads from the standard library i.e. Lib / in the same python process?

Second, if it's safe, is it a bad idea?


source to share

2 answers

This gevent < 1.0

is most likely a bad idea since it is libevent

not thread safe. You might be fine if you make sure that OS threads never interact with libevent

... But it can be tricky, and errors caused by libevent

lack of thread safety don't seem fun to debug.

It does gevent >= 1.0

use however libev

, which is completely thread safe. So (as far as I can tell) there is no problem mixing green streams and OS streams.



gevent provides monkey patching capabilities for threads.

Greenlets only switch to each other within the same stream, so one green thread will be completely separate and without communication with the outside world.

I would not suggest using multiple streams of green until you have shown that you need to get the job done.



All Articles