python协程gevent方式

import gevent
from gevent import monkey
import time

monkey.patch_all()

def work1():
    for i in range(5):
        print("work1:", i)
        time.sleep(0.2)


def work2():
    for i in range(5):
        print("work2:", i)
        time.sleep(0.2)


g1 = gevent.spawn(work1)
g2 = gevent.spawn(work2)

g1.join()
g2.join()

print("==========")
exit()

你可能感兴趣的:(python协程gevent方式)