0
您好我想在這裏運行兩個線程function1
和function2
。我什麼function1
先運行,而function1
暫停在time.sleep(1000)
。我專家function2
立即開始與function1
一起,並繼續其功能。並行線程無需等待python中的其他線程
import thread
import time
# Define a function for the thread
def function1(threadName, delay):
print "%s: %s" % (threadName, time.ctime(time.time()))
time.sleep(1000)
def function2(threadName, delay):
count = 0
while count < 5:
time.sleep(delay)
count += 1
print "%s: %s" % (threadName, time.ctime(time.time()))
# Create two threads as follows
try:
thread.start_new_thread(function1, ("Thread-1", 2,))
thread.start_new_thread(function2, ("Thread-2", 4,))
except:
print "Error: unable to start thread"
while True:
pass
返回
Thread-1: Tue Sep 22 19:10:03 2015