这是我第一次学习 python,我继续尝试从这篇博客文章中进行线程化。问题是它似乎已经过时了:
import time
from threading import Thread
def myfunc(i):
print ("sleeping 5 sec from thread %d" % i)
time.sleep(5)
print ("finished sleeping from thread %d" % i)
for i in range(10):
t = Thread(target=myfunc, args=(i,))
t.start()
如何运行此代码而不会出现此错误:
$ python helloworld.py
Traceback (most recent call last):
File "helloworld.py", line 1, in <module>
import threading
File "c:\Documents and Settings\Hermione\learningPython\threading.py", line 2, in <module>
from threading import Thread
ImportError: cannot import name Thread
奇怪threading.py
的是,我已经删除了那个文件(并且它一直出现!!)和一个神秘的__PyCache__
文件夹。