![](/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.