同时运行多个Python脚本,然后依次运行 [英] Running multiple Python scripts simultaneously and then sequentially

查看:96
本文介绍了同时运行多个Python脚本,然后依次运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从bash脚本中同时运行多个Python脚本;

I can run multiple Python scripts simultaneously from a bash script like this;

#!/bin/bash
python pr1.py & 
python pr2.py &
python aop.py &
python loader.py &

但是,如果我希望一批同时启动,并且在它们运行后又要依次启动,该怎么办?这行得通吗?:

But what if I want a batch to fire simultaneously and after they've run, start some more sequentially. Will this work?:

#!/bin/bash
python pr1.py & 
python pr2.py &
python ap.py &
python loader.py
python cain.py
python able.py

推荐答案

在bash脚本上,您可以像这样简单地添加 wait 命令:

On your bash script you can simply add the wait command like this:

#!/bin/bash
python pr1.py & 
python pr2.py &
python ap.py &
wait
python loader.py
python cain.py
python able.py

显然,

wait 将等待所有作业(您触发的后台过程)完成才能继续.

wait will, obviously, wait for all the jobs (the background proccess you fired) to be finished for it to continue.

这篇关于同时运行多个Python脚本,然后依次运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆