1 from greenlet import greenlet 2 def test1(): 3 print(12) 4 gr2.switch() 5 print(34) 6 gr2.switch() 7 def test2(): 8 print(56) 9 gr1.switch() 10 print(78) 11 gr1=greenlet(test1) 12 gr2=greenlet(test2) 13 gr1.switch()
感觉确实用着比generator还简单了呢,但好像还没有解决一个问题,就是遇到IO操作,自动切换,对不对?