为什么导入多处理时出现导入错误?

时间:2013-08-12 17:22:45

标签: python multiprocessing python-3.3 traceback

我有一个需要多处理的脚本。我从这个脚本中发现的是多处理模块存在问题。为了测试这个理论,我复制并粘贴了

from multiprocessing import Process

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

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

进入测试脚本并收到以下追溯

Traceback (most recent call last):
  File "a.py", line 1, in <module>
    from multiprocessing import Process
  File "/usr/lib64/python3.3/multiprocessing/__init__.py", line 40, in <module>
    from multiprocessing.util import SUBDEBUG, SUBWARNING
  File "/usr/lib64/python3.3/multiprocessing/util.py", line 16, in <module>
    import threading        # we want threading to install it's
  File "/usr/lib64/python3.3/threading.py", line 11, in <module>
    from traceback import format_exc as _format_exc
  File "/usr/lib64/python3.3/traceback.py", line 3, in <module>
    import linecache
  File "/usr/lib64/python3.3/linecache.py", line 10, in <module>
    import tokenize
  File "/usr/lib64/python3.3/tokenize.py", line 30, in <module>
    from token import *
  File "/home/lucas/Server/ClinApp/weblabs/utils/token.py", line 1, in <module>
    from django.conf import settings
  File "/usr/lib/python3.3/site-packages/django/conf/__init__.py", line 9, in <module>
    import logging
  File "/usr/lib64/python3.3/logging/__init__.py", line 195, in <module>
    _lock = threading.RLock()
AttributeError: 'module' object has no attribute 'RLock'

另外,我在四核常春藤桥上运行64位的fedora 18。为什么我收到此回溯错误?

建议

以下是我运行RLock时会发生什么

$ python3
>>> import threading
>>> threading.RLock()
<_thread.RLock owner=0 count=0>
>>> 

2 个答案:

答案 0 :(得分:10)

File "/usr/lib64/python3.3/tokenize.py", line 30, in <module>
    from token import *
File "/home/lucas/Server/ClinApp/weblabs/utils/token.py", line 1, in <module>
    from django.conf import settings

正在导入/home/lucas/Server/ClinApp/weblabs/utils/token.py脚本,而不是标准的python'token.py'。它有一个错误,或者它不应该作为顶级脚本导入。您可能在某种程度上在python路径中有/ home / lucas / Server / ClinApp / weblabs / utils /。

通常,在内置脚本之后命名python脚本不是一个好主意。

答案 1 :(得分:0)

token.py重命名为其他内容(get_token.py)后,请记住在本地工作目录中删除token.pyc。否则,您将继续收到上面列出的Traceback错误消息。