Search code examples
pythonbatch-fileinteractionsungridengine

How can python wait for a batch SGE script finish execution?


I have a problem I'd like you to help me to solve.

I am working in Python and I want to do the following:

  • call an SGE batch script on a server
  • see if it works correctly
  • do something

What I do now is approx the following:

    import subprocess
    try:
       tmp = subprocess.call(qsub ....)
       if tmp != 0:
           error_handler_1()
       else:
           correct_routine()
    except:
       error_handler_2()

My problem is that once the script is sent to SGE, my python script interpret it as a success and keeps working as if it finished.

Do you have any suggestion about how could I make the python code wait for the actual processing result of the SGE script ?

Ah, btw I tried using qrsh but I don't have permission to use it on the SGE

Thanks!


Solution

  • From your code you want the program to wait for job to finish and return code, right? If so, the qsub sync option is likely what you want:

    http://gridscheduler.sourceforge.net/htmlman/htmlman1/qsub.html