fanhuasijin 2019-12-17
手动协程操作:
# pip install gevent from greenlet import greenlet def test(): print(‘He ‘) gr2.switch() print(‘a ‘) gr2.switch() def test2(): print(‘is ‘) gr1.switch() print(‘student.‘) gr1 = greenlet(test) gr2 = greenlet(test2) gr1.switch()
2. 自动协程,遇到I/O自动切换