【问题标题】:Ubuntu 10.04 - Python multiprocessing - 'module' object has no attribute 'local' errorUbuntu 10.04 - Python 多处理 - “模块”对象没有属性“本地”错误
【发布时间】:2010-10-13 04:27:54
【问题描述】:

以下代码来自python 2.6手册。

from multiprocessing import Process
import os

def info(title):
    print(title)
    print('module name:', 'me')
    print('parent process:', os.getppid())
    print('process id:', os.getpid())

def f(name):
    info('function f')
    print('hello', name)

if __name__ == '__main__':
    info('main line')
    p = Process(target=f, args=('bob',))
    p.start()
    p.join()

这将创建以下堆栈跟踪:

Traceback (most recent call last):
  File "threading.py", line 1, in <module>
    from multiprocessing import Process
  File "/usr/lib/python2.6/multiprocessing/__init__.py", line 64, in <module>
    from multiprocessing.util import SUBDEBUG, SUBWARNING
  File "/usr/lib/python2.6/multiprocessing/util.py", line 287, in <module>
    class ForkAwareLocal(threading.local):
AttributeError: 'module' object has no attribute 'local'
Exception AttributeError: '_shutdown' in <module 'threading' from '/home/v0idnull/tmp/pythreads/threading.pyc'> ignored
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/usr/lib/python2.6/multiprocessing/util.py", line 258, in _exit_function
    info('process shutting down')
TypeError: 'NoneType' object is not callable
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/usr/lib/python2.6/multiprocessing/util.py", line 258, in _exit_function
    info('process shutting down')
TypeError: 'NoneType' object is not callable

我完全不知道为什么会发生这种情况,而且谷歌给我的工作很少。

【问题讨论】:

    标签: multiprocessing ubuntu-10.04 python-2.6


    【解决方案1】:

    该代码在我的机器上运行良好:
    Ubuntu 10.10,Python 2.6.6 64 位。

    但您的错误实际上是因为您有一个名为“threading.py”的文件,您正在从中运行此代码(请参阅堆栈跟踪详细信息)。这会导致命名空间不匹配,因为多处理模块需要“真正的”线程模块。尝试将您的文件重命名为“threading.py”以外的名称并再次运行它。

    另外...您发布的示例不是来自 Python 2.6 文档...它来自 Python 3.x 文档。确保您正在阅读与您正在运行的版本相匹配的文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-24
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      • 2020-07-02
      • 1970-01-01
      • 2017-01-31
      相关资源
      最近更新 更多