1. 程式人生 > >AttributeError: 'module' object has no attribute 'Process'(關鍵詞:Python/bug/debug/模組/模組)

AttributeError: 'module' object has no attribute 'Process'(關鍵詞:Python/bug/debug/模組/模組)

multiprocessing.py

import multiprocessing

def work():
        print 'Worker'
        return

if __name__ == '__main__':
        jobs = []
        for i in range(5):
                p = multiprocessing.Process(target=worker)
                jobs.append(p)
                p.start()

報錯:

$ python multiprocessing.py
Traceback (most recent call last):
  File "multiprocessing.py", line 10, in <module>
    p = multiprocessing.Process(target=worker)
AttributeError: 'module' object has no attribute 'Process'

解決辦法:
python 檔案 的 名稱不要與內建模組重名。

參考文獻:

  1. Python指令碼報錯AttributeError: ‘module’ object has no attribute’xxx’解決方法;
  2. module ‘multiprocessing’ has no attribute ‘Process’