# -*- coding: utf-8 -*-
import pymongo
import time
import threading
def threadFunc(threadName):
print("\r\n%s start" % threadName)
time.sleep(5)
print("\r\n%s end" % threadName)
pass
start = time.time()
threads = []
for index in range(0,3):
thread = threading.Thread(target=threadFunc, args=("Thread%s" % index,))
thread.start()
threads.append(thread)
for t in threads:
t.join()
print("thread finished , cost %s s" % (time.time() - start))
控制台输出
Thread0 start
Thread1 start
Thread2 start
Thread1 end
Thread0 end
Thread2 end
thread finished , cost 5.01 s