[英]No print output from child multiprocessing.Process unless the program crashes
I am having trouble with the Python multiprocessing module. 我遇到了Python多处理模块的问题。 I am using the
Process
class to spawn a new process in order to utilize my second core. 我正在使用
Process
类来生成一个新进程,以便利用我的第二个核心。 This second process loads a bunch of data into RAM and then waits patiently instead of consuming. 第二个过程将一堆数据加载到RAM中,然后耐心等待而不是消耗。
I wanted to see what that process printed with the print
command, however, I do not see anything that it prints. 我想看看使用
print
命令print
进程,但是,我没有看到它打印的任何内容。 I only see what the parent process prints. 我只看到父进程打印的内容。 Now this makes sense to me since they live in two different process.
现在这对我来说很有意义,因为他们生活在两个不同的过程中。 The second process doesn't spawn its own shell/standard output window, nor is its output sent to the parent.
第二个进程不会生成自己的shell /标准输出窗口,也不会将其输出发送给父进程。 Yet when this process crashs, it prints everything that my script told it to print, plus the stack trace and error.
然而,当这个过程崩溃时,它会打印我的脚本告诉它打印的所有内容,以及堆栈跟踪和错误。
I am wondering if there is a simple way to send the child process's print output to the first process, or have it spawn a shell/standard output so that I may debug it. 我想知道是否有一种简单的方法将子进程的打印输出发送到第一个进程,或者让它生成一个shell /标准输出,以便我可以调试它。 I know I could create a
multiprocessing.Queue
dedicated to transmitting prints to the parent so that it may print these to standard output, but I do not feel like doing this if a simpler solution exists. 我知道我可以创建一个
multiprocessing.Queue
专门用于将打印件传输到父级,以便它可以将这些打印到标准输出,但如果存在更简单的解决方案,我不想这样做。
Have you tried flushing stdout? 你试过冲洗stdout吗?
import sys
print "foo"
sys.stdout.flush()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.