在Linux Shell脚本中并行运行python命令 [英] Run python commands in parallel in Linux shell scripting

查看:129
本文介绍了在Linux Shell脚本中并行运行python命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,该脚本通过命令行参数从用户那里获取输入.它处理参数并开始运行python命令.例如:

I have a script which gets input from the user through command line arguments. It processes the arguments and starts running python commands. For Example:

./run.sh p1 p2 p3 p4
python abc.py p1 p4
python xyz.py p2 p3 

其中 p1 p2 p3 p4 可以是任何类型.

where p1, p2, p3 and p4 can be of any type.

我需要在两个不同的终端中并行运行这两个python命令.我该怎么做,这样我就不必等待一个命令完成就可以开始下一个命令了?

I need to run both of these python commands in parallel and in two different terminals. How can I do it so that I don't need to wait for 1 command to finish in order to start the next command?

我尝试了GNU并行,但似乎不起作用.

I tried GNU parallel but it doesn't seem to work.

推荐答案

尝试在后台运行每个进程,方法是在命令末尾添加& .

Try running each process in the background by adding & to the end of the command.

python script1.py arg1 arg2 &
python script2.py arg1 arg2 &

echo "Running scripts in parallel"
wait # This will wait until both scripts finish
echo "Script done running"

更多信息

这篇关于在Linux Shell脚本中并行运行python命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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