0
我想測試這個簡單的代碼,我發現在Pydev使用線程模塊,因爲線程模塊不是我的選項。線程甚至不運行,它所做的只是打印HELLO並退出程序。我用我的原始程序使用這個模塊,但它做的是同樣的事情,所以我想我會從源碼的簡單測試開始。這是爲什麼發生?Python線程模塊
代碼:
import thread
import time
# Define a function for the thread
def print_time(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(print_time, ("Thread-1", 2,))
thread.start_new_thread(print_time, ("Thread-2", 4,))
except:
print "Error: unable to start thread"
print "HELLO"
它甚至不產生任何錯誤或異常。
真棒謝謝你! – shapiro