6

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

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'

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

建议

这是我运行 RLock 时发生的情况

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

2 回答 2

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 脚本并不是一个好主意。

于 2013-08-12T17:29:17.303 回答
0

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

于 2017-08-25T20:15:09.640 回答