Python 多处理错误 'ForkAwareLocal' 对象没有属性 'connection' [英] Python multiprocessing error 'ForkAwareLocal' object has no attribute 'connection'

查看:668
本文介绍了Python 多处理错误 'ForkAwareLocal' 对象没有属性 'connection'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码,我正面临着一个多处理问题.我看到以前有人问过这个问题,我已经尝试过这些解决方案,但似乎不起作用.有人可以帮我吗?

Below is my code , for which i am facing a multiprocessing issue. I see this question has been asked before and i have tried those solutions but it does not seem to work. Can someone help me out here ?

from multiprocessing import Pool, Manager


Class X:
    def _init_():


    def method1(number1,var_a, var_b, var_c, var_d):

    return values 

if __name__ == 'main':


    for value in ["X", "Y"]:
        dict_values = Manager().dict()
        with Pool(1) as p:
            p.starmap(method1,
                      [
                          (1, dict_values, var_a, var_b, var_c, var_d),
                          (2, dict_values, var_a, var_b, var_c, var_d),
                          (3, var_a, var_b, var_c, var_d)
                      ])

我面临的错误

multiprocessing.pool.RemoteTraceback: 

Traceback (most recent call last):
  File "/usr/lib64/python3.6/multiprocessing/managers.py", line 749, in _callmethod
    conn = self._tls.connection
AttributeError: 'ForkAwareLocal' object has no attribute 'connection'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.6/multiprocessing/pool.py", line 119, in worker
    result = (True, func(*args, **kwds))
  File "/usr/lib64/python3.6/multiprocessing/pool.py", line 47, in starmapstar
    return list(itertools.starmap(args[0], args[1]))
  File "<string>", line 2, in __setitem__
  File "/usr/lib64/python3.6/multiprocessing/managers.py", line 753, in _callmethod
    self._connect()
  File "/usr/lib64/python3.6/multiprocessing/managers.py", line 740, in _connect
    conn = self._Client(self._token.address, authkey=self._authkey)
  File "/usr/lib64/python3.6/multiprocessing/connection.py", line 487, in Client
    c = SocketClient(address)
  File "/usr/lib64/python3.6/multiprocessing/connection.py", line 614, in SocketClient
    s.connect(address)
FileNotFoundError: [Errno 2] No such file or directory

推荐答案

这个问题的根本原因是主线程做完导致两个进程之间的连接崩溃.然而,子进程仍在运行,它需要通过队列抛出东西.所以保持主线程存活是我们的解决方案.

The root cause of this problem is the main thread is done so crash the connection between two processes. However, the subprocess is still running and it needs to throw stuff out via the queue. So keep the main thread alive is our solution.

https:///jaime-lin.medium.com/python-multiprocessing-manager-error-forkawarelocal-object-has-no-attribute-496009c94aed

这篇关于Python 多处理错误 'ForkAwareLocal' 对象没有属性 'connection'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆