所以在通过pycharm运行时将gevent升级到1.1rc4(从1.0.2)后,我无法让greenlets正确加入......以这段代码为例:
from gevent import monkey, Greenlet, hub
import gevent
hub.Hub.resolver_class = ['gevent.resolver_ares.Resolver']
monkey.patch_all()
def sleepy(time):
gevent.sleep(time)
print "done like a good script"
if __name__ == '__main__':
g = gevent.spawn(sleepy,10)
g.start()
g.join()
print "if this is the only log line, then join didn't work"
将输出:
"if this is the only log line, then join didn't work"
在 IDE 中,它使用 CLI 中的相同解释器正常执行
我遵循了 cli 和 gui 中的代码,并且由于以下行为greenlet.join()
的变化而导致行为有所不同hub.switch()
:
def switch(self):
switch_out = getattr(getcurrent(), 'switch_out', None)
if switch_out is not None:
switch_out()
return greenlet.switch(self)
在执行greenlet之前,最后一行将立即返回... pycharm调试器不会让我进入该代码...
任何帮助都会很棒......协程流控制在工作时已经够难了......