【问题标题】:How to fix the broken pipe error in the following code?如何修复以下代码中的损坏管道错误?
【发布时间】:2019-08-23 13:05:29
【问题描述】:

当我运行以下代码部分时,它会生成一个损坏的管道错误。我该如何解决这个问题?该错误通常是指代理 [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:\ProgramData\Anaconda3\lib\multiprocessing\process.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:\ProgramData\Anaconda3\lib\multiprocessing\context.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:\ProgramData\Anaconda3\lib\multiprocessing\context.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:\ProgramData\Anaconda3\lib\multiprocessing\popen_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:\ProgramData\Anaconda3\lib\multiprocessing\reduction.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

【问题讨论】:

  • 这可能取决于agent 函数中发生的情况,未显示。因此,这里没有足够的上下文来给出有意义的答案。此外,如果您遇到异常,请将完整的回溯添加到您的问题中。
  • @RolandSmith 感谢您的评论。我会将完整的回溯添加到问题中
  • @RolandSmith 我已将完整的追溯添加到我的问题中。

标签: python multiprocessing broken-pipe


【解决方案1】:

从追溯中可以清楚地看出,您在 ms-windows 上使用来自 IPython 的 multiprocessing

不幸的是,这不是很好。 AFAICT,它与 IPython 如何在笔记本中运行代码以及 multiprocessing 如何在 ms-windows 上工作有关。

尝试将您的代码保存在一个文件中,然后从命令行而不是在 IPython 中运行该脚本。

【讨论】:

  • 感谢您的回答。你能指导我如何在我的电脑上做到这一点。我已经安装了 jupyter,但我不知道如何打开 python 命令提示符。
  • @FrankMoses 我不是 ms-windows 用户,所以我帮不了你。
猜你喜欢
  • 2011-01-19
  • 2014-07-30
  • 1970-01-01
  • 1970-01-01
  • 2016-07-21
  • 1970-01-01
  • 2014-04-28
  • 2011-02-12
相关资源
最近更新 更多