2020
09-25
09-25
Python greenlet和gevent使用代码示例解析
greenlet示例greenlet微线程,允许在线程中手动切换示例1,线程切换fromgreenletimportgreenletdeftest1(x,y):z=gr2.switch(x+y)print(z)deftest2(u):print(u)gr1.switch(42)gr1=greenlet(test1)gr2=greenlet(test2)gr1.switch("hello",'world')gr1和gr2是两个greenlet线程,使用gr1.switch(..)启动gr1,gr1执行test1,切换到gr2,gr2执行test2打印helloworld,然后切换回gr1,z获取到返回值42,并打印.执行顺序为:gr1.s...
继续阅读 >