gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 14:01:51 24 4
gpt4 key购买 nike

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

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

最佳答案

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 - 为什么在导入多处理时出现导入错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18192967/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com