SimpleDao
gevent协程
2019-05-06, 访问数: 936

模拟多线程运行

  1. from gevent import monkey
  2. monkey.patch_all()
  3. import gevent
  4. def foo():
  5. print('Running in foo')
  6. gevent.sleep(0)
  7. print('Explicit context switch to foo again')
  8. def bar():
  9. print('Explicit context to bar')
  10. gevent.sleep(0)
  11. print('Implicit context switch back to bar')
  12. gevent.joinall([
  13. gevent.spawn(foo),
  14. gevent.spawn(bar),
  15. ])