Austin Downey
Austin Downey

Reputation: 1055

Wait of abacus job to complete when launched from python script

I am trying to run an Abaqus script from Python through the command prompt on a Windows 8 machine.

The issue I am having is I cannot get the Python script to wait until the Abaqus job has completed before moving forward.

Below is some code that I have tried, one at a time:

os.popen('abaqus job=plate ask_delete=OFF')
os.system('abaqus job=plate ask_delete=OFF')
os.system('abaqus job=plate ask_delete=OFF')
subprocess.call('abaqus job=plate ask_delete=OFF',shell=True)
subprocess.check_call('abaqus job=plate ask_delete=OFF',shell=True)

I have also tried using the wait command after the subprocess tools like this:

p1 = subprocess.check_call('abaqus job=plate ask_delete=OFF',shell=True)
p1.wait()

But I get the error: AttributeError: 'int' object has no attribute 'wait'.

I do not want to use a time.sleep() as this causes a fair amount of down time in my code. I am using Python 3.5.2 and Anaconda 4.2.0 (64-bit).

Upvotes: 1

Views: 1050

Answers (2)

will
will

Reputation: 377

You need to include the abaqus keyword "interactive". e.g.

abaqus myjob=bob1 ask_delete=off interactive

Otherwise it will run in the background and all output goes to bob1.log Also, there is a builtin python environment with the abaqus installation that can be used to automate running abaqus jobs. There are more options for job control and monitoring if you use this "abaqus" python

Upvotes: 5

Maurice Meyer
Maurice Meyer

Reputation: 18106

Both functions call(...) and check_call(...) wait by default for the command to complete. Just for debugging, call the command through Popen and run 'abaqus' with full path 'C:\...\abaqus.exe ...'.

import subprocess

cmd = subprocess.Popen('abaqus job=plate ask_delete=OFF', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out, err = cmd.communicate()
code = cmd.returncode

print(code) # should 0 to indicate the command run successfully
print(out)  # what was piped to stdout
print(err)  # what was piped to stderr

Upvotes: 2

Related Questions