当我运行以下部分代码时,它会产生一个断开的管道错误。如何解决此问题?该错误通常是指代码行,其中显示 agent[0].start((。谢谢。
def main():
np.random.seed(RANDOM_SEED)
assert len(PACKET_SIZE) == A_DIM
# create result directory
if not os.path.exists(SUMMARY_DIR):
os.makedirs(SUMMARY_DIR)
# inter-process communication queues
net_params_queues = []
exp_queues = []
for i in range(NUM_AGENTS):
net_params_queues.append(mp.Queue(1))
exp_queues.append(mp.Queue(1))
# create a coordinator and multiple agent processes
# (note: threading is not desirable due to python GIL)
coordinator = mp.Process(target=central_agent,
args=(net_params_queues, exp_queues))
coordinator.start()
all_cooked_time, all_cooked_bw, _ = load_trace.load_trace(TRAIN_TRACES)
agents = []
print(NUM_AGENTS)
for i in range(NUM_AGENTS):
agents.append(mp.Process(target=agent,
args=(i, all_cooked_time, all_cooked_bw,
net_params_queues[i],
exp_queues[i])))
#print(agents)
#for i in range(NUM_AGENTS):
agents[0].start()
# wait unit training is done
coordinator.join()
if __name__ == '__main__':
main()
完整的回溯如下所示。如果非常必要,我可以添加程序的完整代码。我从某个地方复制了它,我正在尝试理解它。
BrokenPipeError Traceback (most recent call last)
<ipython-input-24-152dc3806edb> in <module>
332
333 if __name__ == '__main__':
--> 334 main()
<ipython-input-24-152dc3806edb> in main()
325 #print(agents)
326 #for i in range(NUM_AGENTS):
--> 327 agents[0].start()
328
329 # wait unit training is done
C:ProgramDataAnaconda3libmultiprocessingprocess.py in start(self)
110 'daemonic processes are not allowed to have children'
111 _cleanup()
--> 112 self._popen = self._Popen(self)
113 self._sentinel = self._popen.sentinel
114 # Avoid a refcycle if the target function holds an indirect
C:ProgramDataAnaconda3libmultiprocessingcontext.py in _Popen(process_obj)
221 @staticmethod
222 def _Popen(process_obj):
--> 223 return _default_context.get_context().Process._Popen(process_obj)
224
225 class DefaultContext(BaseContext):
C:ProgramDataAnaconda3libmultiprocessingcontext.py in _Popen(process_obj)
320 def _Popen(process_obj):
321 from .popen_spawn_win32 import Popen
--> 322 return Popen(process_obj)
323
324 class SpawnContext(BaseContext):
C:ProgramDataAnaconda3libmultiprocessingpopen_spawn_win32.py in __init__(self, process_obj)
63 try:
64 reduction.dump(prep_data, to_child)
---> 65 reduction.dump(process_obj, to_child)
66 finally:
67 set_spawning_popen(None)
C:ProgramDataAnaconda3libmultiprocessingreduction.py in dump(obj, file, protocol)
58 def dump(obj, file, protocol=None):
59 '''Replacement for pickle.dump() using ForkingPickler.'''
---> 60 ForkingPickler(file, protocol).dump(obj)
61
62 #
BrokenPipeError: [Errno 32] Broken pipe
从回溯中可以清楚地看出,您正在使用 ms-windows 上的 IPythonmultiprocessing
。
不幸的是,这效果不佳。AFAICT,它与IPython如何在笔记本中运行代码以及multiprocessing
如何在ms-windows上工作有关。
尝试将代码保存在文件中,并从命令行而不是在 IPython 中运行该脚本。