我想在超级计算机节点的 3 个独立核心处理器上执行 3 个独立的 bash 命令。 我有一个 python 脚本,它通过 os.system 将 bash 命令发送到命令行,但是它似乎在进入 python 脚本中的下一行之前先执行完 bash 命令。我只想将 bash 命令一个接一个地发送到命令行。
for i in range(0, len(core), 8) :
os.system("bpsh "+str(1)+" nohup python /home/tree_df_unchuncked.py "+str(' '.join(core[i]))+" 0.01"+" y")
os.system("bpsh "+str(1)+" nohup python /home/tree_df_unchuncked.py "+str(' '.join(core[i+1]))+" 0.01"+" y")
os.system("bpsh "+str(1)+" nohup python /home/tree_df_unchuncked.py "+str(' '.join(core[i+2]))+" 0.01"+" y")
考虑从 python 程序构建 shell 脚本文件,然后执行该 shell 脚本。当您构建 shell 脚本时,请在每行末尾放置一个 &。将 wait 命令放在程序末尾也很有用,这样 shell 脚本将暂停,直到所有后台命令(并行运行)完成。
#/bin/bash
a &
b &
c &
wait
如果您的代码已格式化,我可以给您一个更具体的答案,以便我可以复制并粘贴它,然后执行它。