首页 > 解决方案 > 在 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 或键盘中断,这就是追溯公开的方式。

标签: python-3.x

解决方案


推荐阅读