Submit a job, wait for its completion and after submit another job

jpcgandre picture jpcgandre · Mar 11, 2012 · Viewed 30.6k times · Source

I need to run multiple times the same abaqus .inp file (slightly changed within runs) and after each run ends I need to submit a abaqus python script that will read the results.

I've done the following:

#run the programme
os.system('abaqus job=file_name cpus=2')

#get results and write them to myresults.txt
os.system('abaqus viewer noGUI=python_name.py')

However, the main program executes the second line before the program started in the first line ends. As a result I get an error. How can I solve this?

Answer

Francisco Cruz picture Francisco Cruz · May 7, 2015

I guess the problem here is not about subprocess waiting (indeed it waits) but the fact that after running the solver, Abaqus takes some seconds to delete some temp files and close its odb. I suggest one of the following:

  • run the solver from the command line with 'interactive' as @glenn_gould proposed

    strCommandLine = 'abaqus interactive job=jobname'  
    subprocess.call(strCommandLine)
    
  • run an abaqus python script

    strCommandLine = 'abaqus python ScriptToRun.py -- (jobname)'  
    subprocess.call(strCommandLine)
    

    and within ScriptToRun.py use waitForCompletion() as @ellumini proposed

    from abaqus import *
    import job
    import sys
    
    jobname = mdb.JobFromInputFile(sys.argv[-1], sys.argv[-1]+".inp") 
    jobname.submit() 
    jobname.waitForCompletion()
    
  • use a try statement to run while file jobname.023 or jobname.lck exist, something like:

    strCommandLine = 'abaqus job=jobname'  
    subprocess.call(strCommandLine)
    
    while os.path.isfile('jobname.023') == True:
        sleep(0.1)
    

This was my first post in this magnificent community, I'd be glad to know if I did something wrong.