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
抛出以下错误。
文件"threading.py",第1行
从线程中导入时间
^ SyntaxError: invalid syntax
对于您指出的错误,这是因为import语句应该是这样的:from threading import time