Reputation: 1994
I have the following python code:
try:
subprocess.check_output('service uwsgi stop;pkill -f uwsgi', shell = True)
except:
sys.exit(0)
it should return always 0 but when I run it, it prints 'Terminated' and then I receive a non-zero return code.
Upvotes: 0
Views: 44
Reputation: 126
Right now, sys.exit(0)
will only be called when an exception is raised. To ensure that it is called every time, add a finally statement:
try:
subprocess.check_output('service uwsgi stop;pkill -f uwsgi', shell = True)
except:
# Handle the exception
finally:
sys.exit(0)
Upvotes: 2