2013-01-06 50 views
0

我的Python代碼:蟒蛇找不到屬性主題

#!/usr/bin/env python 
import threading 
from time import sleep,ctime 
loops=[4,2] 

def loop(nloop,nsec): 
    print 'start loop',nloop,'at:',ctime() 
    sleep(nsec) 
    print 'loop',nloop,'done at:',ctime() 

def main(): 
    print 'starting at:',ctime() 
    threads=[] 
    nloops = range(len(loops)) 

    for i in nloops: 
     t = threading.Thread(target = loop, args = (i,loops[i])) 
     threads.append(t) 
    for i in nloops: 
     threads[i].start() 
    for i in nloops: 
     threads[i].join() 
    print 'all Done at:',ctime() 
if __name__ == '__main__': 
    main() 

但是Python輸出是:

t = threading.Thread(target = loop, args = (i,loops[i])) 
AttributeError: 'module' object has no attribute 'Thread' 
Exception AttributeError: '_shutdown' in <module 'threading' 

我重新安裝Python,但這個問題還是有,如何解決呢?

+0

專業提示:報告python問題時,始終包含* full * traceback的錯誤。 –

回答

15

我打賭你有一個名爲threading.py的本地文件,它掩蓋了系統threading模塊。

您可以通過打印threading.__file__驗證這一點:

import threading 
print threading.__file__ 

得到所導入模塊的文件路徑。

將其重命名或刪除,以解決此問題。