2016-08-16 11 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

構文は 'from threading import time'です。 – khelwood

+0

D:\ practice_exercise>パイソン トレースバック(最後の最新の呼び出し)threading.py:スレッドインポート時 ファイルから で ファイル "threading.py"、1行目、 "D:\ practice_exercise \ threading.py"、 1行目、 からスレッドをインポートするとき ImportError:名前の時刻をインポートできません –

+0

これは、存在しないものをインポートしようとしていることを意味します。それについて私ができることは何もありません。 – khelwood

答えて

0

import文がそうようにする必要がありますので、これはです:あなたは「スレッド」と呼ばれるものから、「時間」と呼ばれるものを輸入しようとしている場合
from threading import time

関連する問題