除非程序崩溃,否则子多处理没有打印输出.Process
我遇到了Python多处理模块的问题。我正在使用 Process
类来生成一个新进程,以便利用我的第二个核心。第二个过程将一堆数据加载到RAM中,然后耐心等待而不是消耗。
I am having trouble with the Python multiprocessing module. I am using the Process
class to spawn a new process in order to utilize my second core. This second process loads a bunch of data into RAM and then waits patiently instead of consuming.
我想看看用 print
命令打印的那个进程,但是,我没有看到它的任何内容打印。我只看到父进程打印的内容。现在这对我来说很有意义,因为他们生活在两个不同的过程中。第二个进程不会生成自己的shell /标准输出窗口,也不会将其输出发送到父级。然而,当这个进程崩溃时,它会打印我的脚本告诉它打印的所有内容,以及堆栈跟踪和错误。
I wanted to see what that process printed with the print
command, however, I do not see anything that it prints. 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. Yet when this process crashs, it prints everything that my script told it to print, plus the stack trace and error.
我想知道是否有一种简单的方法可以将子进程的打印输出发送到第一个进程,或者让它生成一个shell /标准输出以便我可以调试它。我知道我可以创建一个 multiprocessing.Queue
专门用于将打印件传输到父级,以便它可以将这些打印到标准输出,但是如果更简单,我不想这样做解决方案存在。
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. 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.
您是否尝试过冲洗标准输出?
Have you tried flushing stdout?
import sys
print "foo"
sys.stdout.flush()