为什么math.factorial在一个线程中表现得如此奇怪?
这是一个例子,它创建了三个线程:
它调用start线程,然后join超时
睡眠和旋转线程按预期工作并立即返回start,然后坐在join超时.
另一方面,析取线程start直到它运行到最后才返回!
import sys
from threading import Thread
from time import sleep, time
from math import factorial
# Helper class that stores a start time to compare to
class timed_thread(Thread):
def __init__(self, time_start):
Thread.__init__(self)
self.time_start = time_start
# Thread that just executes sleep()
class sleep_thread(timed_thread):
def run(self):
sleep(15)
print "st DONE:\t%f" % (time() - time_start)
# Thread that increments a number for a while …Run Code Online (Sandbox Code Playgroud)