![](/img/trans.png)
[英]How can I delay the execution time of a php script, so the python script can finish
[英]How can python wait for a batch SGE script finish execution?
我有一个问题,我希望你帮我解决。
我在Python工作,我想做以下事情:
我现在所做的大概如下:
import subprocess
try:
tmp = subprocess.call(qsub ....)
if tmp != 0:
error_handler_1()
else:
correct_routine()
except:
error_handler_2()
我的问题是,一旦脚本被发送到SGE,我的python脚本会将其解释为成功并继续工作,就像它完成一样。
你有什么建议我怎么能让python代码等待SGE脚本的实际处理结果?
啊,顺便说一句,我尝试使用qrsh,但我没有权限在SGE上使用它
谢谢!
从您的代码中,您希望程序等待作业完成并返回代码,对吧? 如果是这样,qsub同步选项很可能是你想要的:
http://gridscheduler.sourceforge.net/htmlman/htmlman1/qsub.html
更简单处理的附加答案:使用python drmaa模块: 链接 ,允许使用SGE进行更完整的处理。 在文档中提供的功能代码是在这里:只要你把sleeper.sh脚本在同一目录]请注意到-bn选项需要执行一个脚本.SH,否则它在默认情况下需要一个二进制像解释这里
import drmaa
import os
def main():
"""Submit a job.
Note, need file called sleeper.sh in current directory.
"""
s = drmaa.Session()
s.initialize()
print 'Creating job template'
jt = s.createJobTemplate()
jt.remoteCommand = os.getcwd()+'/sleeper.sh'
jt.args = ['42','Simon says:']
jt.joinFiles=False
jt.nativeSpecification ="-m abe -M mymail -q so-el6 -b n"
jobid = s.runJob(jt)
print 'Your job has been submitted with id ' + jobid
retval = s.wait(jobid, drmaa.Session.TIMEOUT_WAIT_FOREVER)
print('Job: {0} finished with status {1}'.format(retval.jobId, retval.hasExited))
print 'Cleaning up'
s.deleteJobTemplate(jt)
s.exit()
if __name__=='__main__':
main()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.