2016-08-16 55 views
-2
import time from threading 
    import thread 

    def myfunc(i): #Each thread runs this function 
    print "sleep from thread %d" % i 
    time. Sleep(5) 
    print "woke up from thread %d" % i 
    return 

    for i in range(10): # Create 10 Thread objects 
    t = Thread(target=myfunc, args=(i,)) 
    t.start() #Start Each Thread 
    return 

它引發以下錯誤。請修復python中的多線程代碼

File "threading.py", line 1
import time from threading
^ SyntaxError: invalid syntax

+0

如果你想從所謂的「線程」導入一種叫做「時間」 ,語法是'從線程導入時間'。 – khelwood

+0

d:\ practice_exercise>蟒蛇threading.py 回溯(最近通話最後一個): 文件 「threading.py」,1號線,在 從穿線進口時間 文件 「d:\ practice_exercise \ threading.py」第1行,在中 從線程導入時間 ImportError:無法導入名稱時間 –

+0

這意味着您正在嘗試導入不存在的內容。我無能爲力。 – khelwood

回答

0

爲你指出了錯誤,這是因爲進口的說法應該是像這樣:
from threading import time