How to fix BrokenPipeError: [Errno 32] (Python, Windows 10)

Hi, I recently attempted to run a black hole simulator (https://github.com/rantonels/starless) coded a couple years ago, and ran into a few problems. The one I’m currently stuck on is one concerning a pipe error, and, being fairly new to Python, I can’t seem to fix it.

This is what the console returns:

    Traceback (most recent call last):
  File "tracer.py", line 925, in <module>
    proc.start()
  File "C:\Users\artur\AppData\Local\Programs\Python\Python36\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "C:\Users\artur\AppData\Local\Programs\Python\Python36\lib\multiprocessing\context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Users\artur\AppData\Local\Programs\Python\Python36\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)
  File "C:\Users\artur\AppData\Local\Programs\Python\Python36\lib\multiprocessing\popen_spawn_win32.py", line 65, in __init__
    reduction.dump(process_obj, to_child)
  File "C:\Users\artur\AppData\Local\Programs\Python\Python36\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
BrokenPipeError: [Errno 32] Broken pipe

I’ve tracked down the bug to the following lines:

process_list = []
for i in range(NTHREADS):
	p = multiprocessing.Process(target=raytrace_schedule,args=(i,schedules[i],total_colour_buffer_preproc_shared,output.queue))
	process_list.append(p)

logger.debug("Starting threads...")
		
for proc in process_list:
    proc.start()

The way I see it, the problem is caused by the multiprocessing library, which must be attempting to write on a closed pipe.

HI,
I think it’s the same issue and solution as here.
Hope this helps :vulcan_salute:

Hi,
Actually, all I needed was an if statement (if __name__ == '__main__':) right before executing the multiprocessing library, as shown here: https://github.com/rantonels/starless/issues/17. I’ll leave this here in case someone needs it. Thanks, though.