gpt4 book ai didi

python子进程一个一个运行

转载 作者:行者123 更新时间:2023-11-28 21:41:02 25 4
gpt4 key购买 nike

我有一些流程:

subprocess.Popen(['python2.7 script1.py')],shell=True)
subprocess.Popen(['python2.7 script2.py')],shell=True)
subprocess.Popen(['python2.7 script3.py')],shell=True)
subprocess.Popen(['python2.7 script4.py')],shell=True)

我希望每一个都在前一个过程完全完成后开始。我是说

subprocess.Popen(['python2.7 script2.py')],shell=True)

开始于

subprocess.Popen(['python2.7 script1.py')],shell=True)

完全完成,其他人也一样。这是因为以前的脚本有输出,它被下一个脚本使用。谢谢

最佳答案

使用subprocess.call :

Run the command described by args. Wait for command to complete, then return the returncode attribute.

在你的例子中:

subprocess.call(['python2.7 script1.py'],shell=True)
subprocess.call(['python2.7 script2.py'],shell=True)
subprocess.call(['python2.7 script3.py'],shell=True)
subprocess.call(['python2.7 script4.py'],shell=True)

关于python子进程一个一个运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45138223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com