I am calling an external program from python 2.7 and as an input to that program I have a few parameters. I do not have access to the code of the program that I am calling. For some combinations of these parameters the program crashes and returns an exit code, and no error; typically "Process finished with exit code -1073741819 (0xC0000005)". What I want to do is: whenever it fails with this exit code I want it to rerun the script with new initial parameters. I tried something along:
parameters1 = [1, 2, 3, 4]
parameters2 = [2, 3, 4, 5]
j = 0
q = 0
while j == 0:
parameter1 = parameters1[q]
parameter2 = parameters2[q]
try:
f3d.run(parameter1 = parameter1, parameter2 = parameter2)
j = 1
except:
pass
CodePudding user response:
While the question is quite unclear, I think this is what you're trying to achieve:
runner.py:
SLEEP_TIME = 3
print('Starting run...')
while True:
exit_code = subprocess.call(['python', 'foo.py', parameter_1, parameter_2])
print('Script Stopped.')
if exit_code == -1073741819:
# change parameter_1 and parameter_2 here
print('Sleeping for %d seconds' % SLEEP_TIME)
time.sleep(SLEEP_TIME)
print('Restarting...')
foo.py:
import sys
parameter_1 = sys.argv[1]
parameter_2 = sys.argv[2]
# Your code here
You run the runner.py
which will keep restarting infinitely.
Also, unwanted advice: Do not use Python2.7. Its outdated.
CodePudding user response:
Thanks a lot for the fast and good answer! This is what I was looking for. I had to use Python2.7 to be compatible with the external software. Have a nice day my good sir/madam!