[英]Downside of using patched threading vs native gevent greenlets?
My understanding is that once I have called gevent.monkey.patch_all(), the standard threading module is modified to use greenlets instead of python threads. 我的理解是,一旦我调用gevent.monkey.patch_all(),标准线程模块就会被修改为使用greenlets而不是python线程。 So if I write my application in terms of python threads, locks, semaphores etc, and then call patch_all, am I getting the full benefit of gevent, or am I losing out on something compared with using the explicit gevent equivalents?
因此,如果我根据python线程,锁,信号量等编写应用程序,然后调用patch_all,我是否可以获得gevent的全部好处,或者与使用显式gevent等效项相比,我是否会失去一些东西?
The motivation behind this question is that I am writing a module which uses some threads/greenlets, and I am deciding whether it is useful to have an explicit switch between using gevent and using threading, or whether I can just use threading+patch_all without losing anything. 这个问题背后的动机是我正在编写一个使用一些线程/ greenlets的模块,我决定在使用gevent和使用线程之间进行显式切换是否有用,或者我是否可以使用线程+ patch_all而不会丢失任何东西。
To put it in code, is this... 把它放在代码中,是这个......
def myfunction():
print 'ohai'
Greenlet.spawn(myfunction)
...any different to this? ......这有什么不同吗?
import gevent.monkey
gevent.monkey.patch_all()
def mythread(threading.Thread):
def run(self):
print 'ohai'
mythread().start()
At least your will loose some of greenlet-specific methods: link, kill, join etc. Also you can't use threads with, for example, gevent.pool module, that can be very useful. 至少你会遗漏一些特定于greenlet的方法:link,kill,join等。另外你不能使用例如gevent.pool模块的线程,这可能非常有用。 And there is a very little overhead for creating Thread object.
创建Thread对象的开销很小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.