运行 一个脚本并行直到另一个脚本完成

Run a script in parallel until another one finishes

我有 2 个 python 脚本 A.py 和 B.py

我想 运行 两者并行,但我想连续多次保持 运行ning B.py 并行,直到 A.py完成

类似于:

A.py &
while A.py not finished :
     B.py &
end while

我很不擅长 shell 编写脚本,谁能告诉我该怎么做?

提前致谢

您可以使用这个循环:

#!/bin/bash

python A.py &

while [[ $(jobs -pr) ]]; do
    python B.py
done

jobs -pr 列出了 运行 个作业(-r)的进程 ID(-p)。如果输出为空,则后台命令已完成。