1.导入eventlet
import eventlet
2.超时退出完整程序:
import time
import eventlet #导入eventlet
eventlet.monkey_patch() #猴子补丁
with eventlet.Timeout(2,False): #设置超时时间为2秒
time.sleep(0.5)
print('执行了第一条')
def MC():
print('MC1')
time.sleep(1)
print('MC2')
time.sleep(1)
print('MC3')
time.sleep(1)
print('MC4')
time.sleep(1)
print('MC4')
with eventlet.Timeout(3,False):#设置超时时间为3秒
MC()
运行效果:
Comments NOTHING