我有一个在多进程中生成另一个函数的代码。有时 start 方法会引发 BrokenPipeError 异常。
我的代码:
process = multiprocessing.Process(target=my_func)
process.daemon = True
process.start()
追溯:
process.start()
File "/usr/lib64/python3.6/multiprocessing/process.py", line 105, in start
self._popen = self._Popen(self)
File "/usr/lib64/python3.6/multiprocessing/context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "/usr/lib64/python3.6/multiprocessing/context.py", line 277, in _Popen
return Popen(process_obj)
File "/usr/lib64/python3.6/multiprocessing/popen_fork.py", line 17, in __init__
util._flush_std_streams()
File "/usr/lib64/python3.6/multiprocessing/util.py", line 401, in _flush_std_streams
sys.stderr.flush()
BrokenPipeError: [Errno 32] Broken pipe
我在这里缺少什么吗?my_func 启动一个新的 RPyC 服务。
def my_func():
inst = MyService()
port = 18600
logger = logging.getLogger(MyService.__name__)
logger.setLevel(logging.WARNING)
while True:
try:
server = ThreadedServer(
inst,
hostname='localhost',
port=port,
protocol_config=PROTOCOL_CONFIG,
auto_register=True,
registrar=UDPRegistryClient(ip='localhost', logger=logger),
logger=logger
)
break
except IOError:
port += 1
server.start()