Python Forum
capture stdout from child processes - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: capture stdout from child processes (/thread-22106.html)



capture stdout from child processes - Skaperen - Oct-30-2019

the parent process, which is not running any threads, will be running more than one child processes (using the multiprocessing module) that will be running things (possibly not Python) that output to stdout. i want the parent to capture this output. apparently, i cannot use multiprocessing.Pipe() since that does not capture stdout. it appears that my only option is to create a system level pipe using os.pipe() and pass the file descriptors to the child so it can close the read end and substitute stdout with the write end before it (the child process) does anything else. but i am afraid that is too Unix specific and not portable enough to run on Windows. does anyone know anything about this? is there a way to code this to be portable?

the parent will not be reading child process data in parallel. instead, it will read each child one at a time in a specific order. it will block until the first child begins to do output. the other child processes will block if they do any output until the parent gets around to reading there output.