python等待执行完成_并行运行Python脚本,并等待所有脚本完成,然后再执行更多并行脚本...

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-17 04:09   29   0

I need to execute my Python scripts in parallel so I use the following batch file for it:

start python C:\myfolder\1.py

start python C:\myfolder\2.py

start python C:\myfolder\3.py

It works fine, but now I need to run three more scripts in parallel AFTER the above first three finish. How can I specify it in the same batch file?

解决方案

You can easily do this in python without using windows batch commands.

You can use the subprocess library to run external scripts simultaneously and then wait for them all to complete.

processes = []

scripts = [

r'C:\myfolder\1.py',

r'C:\myfolder\2.py',

r'C:\myfolder\3.py',

]

for script in scripts:

p = subprocess.Popen(['python', script])

processes.append(p)

for p in processes:

p.wait()

# Run other processes here

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP