gevent module
import gevent,time
from gevent import monkey
monkey.patch_all()
def func1():
print(11111111)
time.sleep(3)
print(22222)
def func2():
print(3333)
time.sleep(4)
print(4444)
g1 = gevent.spawn(func1)
g2 = gevent.spawn(func2)
# time.sleep(6)
# 或
g1.join()
g2.join()
print("我结束了")
Import monkey patch
Call monkey.patch_all ()
This function automatically captures blocked program,
Gevent module to be switched between the coroutine
gevent.spawn (func)
Use spawn function, the return value is an object, and the func set coroutine, concurrently
Call returns the object bound method
PS: In this step, when, func has been performed,
But if the main thread code is over, this thread also followed the end, unable to perform,
so does the use of this module is to report the main thread is still alive
Object .join ()
Blocking the main thread to live, you know coroutine has finished running
Portal
XMind: ZEN - Trial Version