首先,将绿色线程(如Eventlet或Gevent)与来自标准库中的Python本机线程混合,即相同Python进程中的Python本机,I.1个lib / threading.py?

其次,如果它是安全的,这是一个坏主意吗?

有帮助吗?

解决方案

With gevent < 1.0 it is most likely a bad idea, as libevent isn't thread safe. You might be okay if you make sure that the OS threads never interact with libevent… But that could be tricky, and bugs cause by libevent's lack of thread safety don't sound like any fun to debug.

However, gevent >= 1.0 uses libev, which is entirely thread safe. So (as far as I can tell) there's no problem mixing green threads and OS threads.

其他提示

gevent provides monkey patching abilities for threads.

Greenlets only switch to eachother within one thread, so one thread's greenlets will be completely separate and incommunicado from another's.

I wouldn't suggest using multiple threads of greenlets until you've shown you have a performance need to do so.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top