编程语言
首页 > 编程语言> > python – 为什么导入多处理时出现导入错误?

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

作者:互联网

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

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>
>>> 

解决方法:

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

标签:python-3-3,python,multiprocessing,traceback
来源: https://codeday.me/bug/20190723/1508896.html