gevent协程

模拟多线程运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from gevent import monkey
monkey.patch_all()
import gevent

def foo():
print('Running in foo')
gevent.sleep(0)
print('Explicit context switch to foo again')

def bar():
print('Explicit context to bar')
gevent.sleep(0)
print('Implicit context switch back to bar')

gevent.joinall([
gevent.spawn(foo),
gevent.spawn(bar),
])
文章目录
  1. 1. 模拟多线程运行