python-3.x - 在 SIGINT 的多处理过程中避免管道损坏?
问题描述
这不是我所说的典型的破管问题,因为预计会出现破管。我想做的是避免 SIGINT 影响给定的多处理进程的不雅结果。例如,调用捕获多处理进程的键盘中断或 SIGINT:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/usr/local/lib/python3.9/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/noderedlistener/NodeRedListener/_TaskProcessClass.py", line 231, in __target__
self.__message__('{}, Id {}, Time {}'.format(Caption.NotAlive, theId, self.Time))
File "/home/pi/noderedlistener/NodeRedListener/_TaskProcessClass.py", line 250, in Time
return (time.time()-self.__time__.value)
File "/usr/local/lib/python3.9/multiprocessing/managers.py", line 1128, in get
return self._callmethod('get')
File "/usr/local/lib/python3.9/multiprocessing/managers.py", line 808, in _callmethod
conn.send((self._id, methodname, args, kwds))
File "/usr/local/lib/python3.9/multiprocessing/connection.py", line 211, in send
self._send_bytes(_ForkingPickler.dumps(obj))
File "/usr/local/lib/python3.9/multiprocessing/connection.py", line 416, in _send_bytes
self._send(header + buf)
File "/usr/local/lib/python3.9/multiprocessing/connection.py", line 373, in _send
n = write(self._handle, buf)
BrokenPipeError: [Errno 32] Broken pipe
因为执行的实际多处理(模块)代码根本不处理中断或不能处理,对吧?当然,我的代码正在捕获 SIGINT 或键盘中断,这就是追溯公开的方式。
解决方案
推荐阅读
- javascript - 使用JQuery提示用户后如何删除动态表的特定行?
- java - 检查列表是否包含数组的所有元素
- java - 实例变量的验证依赖于另一个实例变量是不好的做法吗?
- html - 如何将许多文本元素并排放置,使您看不到文本之间的区别?
- c - 使用多个进程并行读取多个文件的问题:C 中的 pipe()、for() 和 wait()
- c# - 如何在 WPF 中使用 DocumentViewer 预览文档,每张纸多页
- list - 多个列表的组合 - Prolog
- python - Python - 将请求库链接到我的浏览器
- c# - C# - 调用覆盖方法的基本版本
- tensorflow - 张量流 2.0 中的 spatial_softmax 层