我有一個問題,情況就像下面的代碼。目標函數(等待)處於while循環或花費了很長時間,所以我想殺死微線程。如何殺死thread1?如何在while循環中停止gevent微線程?
import gevent
from gevent import Timeout
def wait():
while(1):
pass
print 'end'
timer = Timeout(1).start()
thread1 = gevent.spawn(wait)
try:
thread1.join(timeout=timer)
except Timeout:
print('Thread 1 timed out')
什麼不起作用? – msvalkon
你可以使用gevent.killall()! –