我可能在某个地方犯了一个小错误,但即使是在multiprocessing.Manager
块中(或不使用)使用with
的最小示例,有时也会出现错误消息:
import logging
import multiprocessing
def test():
logger = multiprocessing.log_to_stderr()
logger.setLevel(logging.INFO)
with multiprocessing.Manager() as m:
print("Shutdown")
print("Done")
if __name__ == "__main__":
test()
预期的结果(大部分时间):
[INFO/SyncManager-1] child process calling self.run()
[INFO/SyncManager-1] created temp directory /tmp/pymp-ovckulfx
[INFO/SyncManager-1] manager serving at '/tmp/pymp-ovckulfx/listener-2huadgai'
Shutdown
[INFO/MainProcess] sending shutdown message to manager
[INFO/SyncManager-1] process shutting down
[INFO/SyncManager-1] process exiting with exitcode 0
Done
[INFO/MainProcess] process shutting down
意外结果(有时会发生):
[INFO/SyncManager-1] child process calling self.run()
[INFO/SyncManager-1] created temp directory /tmp/pymp-1781pg20
[INFO/SyncManager-1] manager serving at '/tmp/pymp-1781pg20/listener-w5fsqqpv'
Shutdown
[INFO/MainProcess] sending shutdown message to manager
[INFO/SyncManager-1] process shutting down
[INFO/SyncManager-1] Failure to send message: ('#RETURN', None)
[INFO/SyncManager-1] ... request was (None, 'shutdown', (), {})
[INFO/SyncManager-1] ... exception was BrokenPipeError(32, 'Broken pipe')
[INFO/SyncManager-1] process exiting with exitcode 0
Done
[INFO/MainProcess] process shutting down
我在Linux上使用Python 3.6.5(默认值,2018年7月6日,09:41:10),[GCC 5.4.0 20160609]