我已經寫了線程非常基本的Python代碼...線程在python面臨麻煩
import time
import thread
def print_hello(name,delay):
while 1:
print name
time.sleep(delay)
try:
thread.start_new_thread(print_hello, ("frist",1,))
thread.start_new_thread(print_hello, ("second",2,))
except:
print "unable to start thread"
time.sleep(4)
print "hello"
其輸出是:
second
frist
frist
second
frist
frist
hello
例外:
Unhandled exception in thread started by
sys.excepthook is missing
lost sys.stderr
Unhandled exception in thread started by
sys.excepthook is missing
lost sys.stderr
我的查詢:
- 爲何再來第一名?
- 爲什麼異常?
有些人在遇到問題時會想「我會用線程」。然後他們有兩個具有錯誤。 –