import time
import threadpool
def test(str):
print str
time.sleep(2)
if __name__ == "__main__":
startTime = time.time()
pool = threadpool.ThreadPool(10)
requests = threadpool.makeRequests(test, args_list=['thread1', 'thread2', 'thread3', 'thread4'])
[pool.putRequest(req) for req in requests]
pool.wait()
endTime = time.time()
print endTime - startTime
單線程執行該方法的結果
def test(str):
print str
time.sleep(2)
if __name__ == "__main__":
startTime = time.time()
for i in range(4):
test(str(i))
endTime = time.time()
print endTime - startTime