目录

错误代码

报错信息

错误原因

解决方法


错误代码

python多进程管理manager时候,当不使用join对当前进程(主进程)进行阻塞时会报错,具体代码及错误如下:

from multiprocessing import Process, Manager
import time
import osdef info(title):print(title)print('module name:', __name__)print('parent process:', os.getppid())print('process id:', os.getpid())print("\n\n")def f(d, l,n):info('\033[32;1m subprocess line\033[0m')d[1] = '1'd['2'] = 2d[0.25] = Nonel.append(n)print(l)if __name__ == '__main__':info('\033[32;1mmain process line\033[0m')with Manager() as manager:d = manager.dict()l = manager.list(range(5))p_list = []for i in range(10):p = Process(target=f, args=(d, l,i))p_list.append(p)# p.join()for p in p_list:p.start()

报错信息

Process Process-11:
Traceback (most recent call last):File "/usr/lib/python3.4/multiprocessing/managers.py", line 724, in _callmethodconn = 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/lib/python3.4/multiprocessing/process.py", line 254, in _bootstrapself.run()File "/usr/lib/python3.4/multiprocessing/process.py", line 93, in runself._target(*self._args, **self._kwargs)File "managerTest.py", line 19, in fd[1] = '1'File "<string>", line 2, in __setitem__File "/usr/lib/python3.4/multiprocessing/managers.py", line 728, in _callmethodself._connect()File "/usr/lib/python3.4/multiprocessing/managers.py", line 715, in _connectconn = self._Client(self._token.address, authkey=self._authkey)File "/usr/lib/python3.4/multiprocessing/connection.py", line 495, in Clientc = SocketClient(address)File "/usr/lib/python3.4/multiprocessing/connection.py", line 624, in SocketClients.connect(address)
FileNotFoundError: [Errno 2] No such file or directory

错误原因

启动工作进程后 主进程立即就结束了,创建multiprocessing.Manager的进程完成执行后,Manager服务器将关闭,这意味着您的共享列表对象现在无用了。

发生这种情况是因为Manager对象将其shutdown函数注册为multiprocessing模块的" finalizer",这意味着它将在进程退出之前运行。这是在BaseManager.__init__中注册它的代码:

# register a finalizer
self._state.value = State.STARTED
self.shutdown = util.Finalize(self, type(self)._finalize_manager,args=(self._process, self._address, self._authkey,self._state, self._Client),exitpriority=0)

这是实际执行关闭操作的代码:

@staticmethod
def _finalize_manager(process, address, authkey, state, _Client):'''Shutdown the manager process; will be registered as a finalizer'''if process.is_alive():util.info('sending shutdown message to manager')try:conn = _Client(address, authkey=authkey)try:dispatch(conn, None, 'shutdown')finally:conn.close()except Exception:passprocess.join(timeout=1.0)if process.is_alive():util.info('manager still alive')if hasattr(process, 'terminate'):util.info('trying to `terminate()` manager process')process.terminate()process.join(timeout=0.1)if process.is_alive():util.info('manager still alive after terminate')state.value = State.SHUTDOWNtry:del BaseProxy._address_to_local[address]except KeyError:pass

解决方法

在主进程中 对子进程进行 join 等待

python3 多进程 multiprocessing 报错 AttributeError: ‘ForkAwareLocal‘ object has no attribute ‘connection‘相关推荐

  1. Scrapy爬虫报错AttributeError: ‘NoneType‘ object has no attribute ‘write‘

    前言 一.报错 AttributeError: 'NoneType' object has no attribute 'write' 二.报错原因 1.piplines文件中的方法不能自定义的呢 开始 ...

  2. 关于在《python编程从入门到实践》书中练习“外星人大战”报错“AttributeError: ‘AlienInvasion‘ object has no attribute ‘blit‘”

    关于在<python编程从入门到实践>书中练习"外星人大战"报错"AttributeError: 'AlienInvasion' object has no ...

  3. 爬虫的自创建请求对象:报错AttributeError: 'str' object has no attribute 'items'

    在使用爬虫库创建自定义请求对象时 将值传入headers agent = random.choice(userAgent) REQ = request.Request(url,headers=agen ...

  4. 运行项目时flask_sqlalchemy报错AttributeError: ‘LocalStack‘ object has no attribute ‘__ident_func__‘

    运行项目时flask_sqlalchemy报错AttributeError: 'LocalStack' object has no attribute '__ident_func__' 1.原因 2. ...

  5. 报错AttributeError: ‘NoneType‘ object has no attribute ‘shape‘

    环境: python3.6.4 opencv3.4.1.15 运行目标跟踪object_tracking文件夹中的mean函数时报错且不显示视频结果 Traceback (most recent ca ...

  6. Python之报错AttributeError:'CocaCola' object has no attribute 'local_logo'

    试运行class类的代码如下,然而有报错信息:AttributeError:'CocaCola' object has no attribute 'local_logo' class CocaCola ...

  7. python 执行报错AttributeError: 'list' object has no attribute 'g'

    ^ SyntaxError: invalid syntax E:\数学-机器学习-西瓜书-周志华\UDACITY购课\project1 矩阵操作>python test.py Traceback ...

  8. coursera-dl 报错 AttributeError (‘HTMLParser’ object has no attribute ‘unescape’)

    参考:https://www.organizingcreativity.com/2021/01/downloading-coursera-materials/ 1.找到utils.py位置 */sit ...

  9. etree.html 报错 AttributeError:‘function’ object has no attribut ‘HTML’

    etree.html 报错 1.Pycharm 中lxml没有etree模块的解决方法: 之前是: from lxml import etree tree = etree.HTML( ) python ...

最新文章

  1. Microsoft Access、MySQL 以及 SQL Server 所使用的数据类型和范围。
  2. 静态主席树总结(静态区间的k大)
  3. 今天才知道css hack是什么
  4. C# 列出进程以及详细信息
  5. 借个iPad玩玩,越狱4.2.1成功
  6. java awt文件上传_springMVC实现前台带进度条文件上传的示例代码
  7. Docker部署项目的两种方式总结
  8. 最近完成的一个可伸缩性的WEB开发框架
  9. 【NOI OpenJudge】【1.2】编程基础之变量定义、赋值及转换
  10. SharePoint 2010 PowerShell 系列 之 Create List and Field --Lookup
  11. 建立网站需要什么条件_教育学校网站建设有什么作用?学校建立网站为的是什么?...
  12. 网络安全实验室CTF—基础关 writeup
  13. 项目启动会发言稿(范文二)
  14. 炒股50问——走向职业操盘的简单问答!
  15. 程序闪退崩溃的几种原因
  16. DAMA数据管理知识体系指南-读书笔记9
  17. 快速做出3D人物动画
  18. paper survey之——水下图像复原与增强水下光通信
  19. 人工智能和机器学习方面重要会议
  20. 多传感器融合方式分析

热门文章

  1. C++中文转码问题(GB2312 - UTF8)
  2. ORACLE-删除同一字段中重复值函数
  3. 架构师之路 — 数据库设计 — 关系型数据库的约束类型
  4. Ironic 裸金属实例的部署流程
  5. 24BYJ48电机的使用,带驱动程序
  6. Simulink仿真---PMSM滞环电流控制仿真模型学习
  7. 理想ONE“偷袭”豪华品牌 李想强调不会收取金融服务费 | 2019上海车展
  8. R语言修改标题、坐标轴刻度、坐标轴名称的大小(cex.axis、cex.lab、cex.main函数)...
  9. 我的Android进阶之旅------gt;怎样在多个LinearLayout中加入分隔线
  10. 转:Object-Runtime的基本数据类型