【发布时间】:2018-04-17 10:50:06
【问题描述】:
我正在使用 python 子进程,如下所示。
import subprocess
p1 = subprocess.Popen(['python', 'test1.py'])
p2 = subprocess.Popen(['python', 'test2.py'])
p1.wait()
p2.wait()
print('The main and sub-processes are finished')
test1.py 和 test2.py 中都有 print 语句。其期望的行为是连续打印“test1”或“test2”。
我期待一种混合输出,因为它们是并行运行的。但是,我只看到“test1”:
test1
test1
test1
and so on.
我在这里错过了什么?
所需的输出:两个打印语句都应该在 STDOUT 上。
注意:这是一个非常简单的问题示例。 注意:想象一下 test1 和 test2 看起来像这样。
test1.py:
for i in range(100000):
print('test1')
test2.py:
for i in range(100000):
print('test2')
【问题讨论】:
标签: python-3.x multiprocessing subprocess