为什么使用多处理会出现 EOFError。经理()?

问题描述 投票:0回答:1

在Python中,要使用

multiprocessing
在不同进程之间共享数据,我们使用
multiprocessing.Manager()
。我想在以下代码中获得输出
[1,2,3,4,5,6,7,8,9,10]
,但我收到 EOFError。为什么? 代码是:

import multiprocessing
manager=multiprocessing.Manager()

final_list=manager.list()
input_list_one=[1,2,3,4,5]
input_list_two=[6,7,8,9,10]

def worker(data):
    for item in data:
        final_list.append(item)

process_1=multiprocessing.Process(target=worker,args=[input_list_one])
process_2=multiprocessing.Process(target=worker,args=[input_list_two])
process_1.start()
process_2.start()
process_1.join()
process_2.join()

print(final_list)

我收到以下错误:

Process SyncManager-1:
Traceback (most recent call last):
  File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/multiprocessing/managers.py", line 539, in _run_server
    server = cls._Server(registry, address, authkey, serializer)
  File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/multiprocessing/managers.py", line 139, in __init__
    self.listener = Listener(address=address, backlog=16)
  File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/multiprocessing/connection.py", line 438, in __init__
    self._listener = SocketListener(address, family, backlog)
  File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/multiprocessing/connection.py", line 576, in __init__
    self._socket.bind(address)
PermissionError: [Errno 13] Permission denied
Traceback (most recent call last):
  File "/storage/emulated/0/qpython/.last_tmp.py", line 2, in <module>
    manager=multiprocessing.Manager()
  File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/multiprocessing/context.py", line 56, in Manager
  File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/multiprocessing/managers.py", line 517, in start
  File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/multiprocessing/connection.py", line 250, in recv
  File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/multiprocessing/connection.py", line 407, in _recv_bytes
  File "/data/user/0/org.qpython.qpy3/files/lib/python36.zip/multiprocessing/connection.py", line 383, in _recv
EOFError
1|u0_a823@land:/ $

python multiprocessing python-multiprocessing
1个回答
0
投票

我偶然发现了同样的问题。 这是我的理解:

  • 子进程尝试绑定到套接字 (线
    self._socket.bind(address)
  • 尝试访问时遇到 PermissionError 并意外关闭
  • 管理器引发 EOFError 因为子进程未绑定

在 Linux 上,套接字通常用

/tmp/pymp-XXXXXXXX/listener-XXXXXXXX
编写。 因此,我建议您检查您的进程是否具有此文件夹的正确权限。

我通过在 Python 代码中使用

os.umask()
设置正确的 umask 解决了权限被拒绝错误。

© www.soinside.com 2019 - 2024. All rights reserved.