gpt4 book ai didi

python - 如何在 python-bash 环境中管理进程?

转载 作者:太空宇宙 更新时间:2023-11-03 20:22:39 25 4
gpt4 key购买 nike

我有一个用于科学计算的Linux服务器。服务器提供bsub < [filename]对于将[文件名]提交到队列,计算将在2小时后返回类似“A.chk”的文件;还有bjobs用于检查所有作业的状态,包括作业ID、运行状态(RUN、PEND、EXIT)等。现在我想满足以下需求:

  1. Submitting A.sh to the server;
  2. Waitting for the calculation terminates, assume that it generates B.chk;
  3. Do another calculation with B.chk and an existing script C.py
  4. Do all these stuff automatically in one .py script.

我已经设法在 python 脚本中获取最新的 jobID 和运行状态。我尝试了以下解决方案:

import os
import time

os.system("bsub < %s" %(A.sh))
job_ID = get_jobID()
while(get_runstatus(jobID) != "RUN" and get_runstatus(jobID) != "PEND"):
time.sleep(30)

if "B.chk" in os.listdir():
os.system("python C.py")

但是服务器中的while循环占用了太多的公共(public)资源,所以我不愿意这样做。然后我搜索了类似 process.join() 的解决方案在 SubProcess 中,但是服务器上的作业序列不能被视为 python 中的子进程。所以我在这里向您寻求更好的解决方案。谢谢。

最佳答案

虽然这并不能完全回答你的问题,但 github 上有一个用于 LSF 的 Python API

https://github.com/IBMSpectrumComputing/lsf-python-api

关于python - 如何在 python-bash 环境中管理进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58054411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com