I have a script with an bail-out function like so:
def die():
from sys import exit
exit()
Occasionally in the script I check a condition and exit if necessary. This works great in 10.1, but unfortunately our server is still at 10. I had to modify the function as follows to work (per this post):
def die():
from sys import exit
try:
exit()
except SystemExit:
pass
The problem is that it gets to the except
, pass
es, and keeps on trucking right to the end of the script. Is there any way to actually make the script stop?
2 Answers 2
You're going to need to wrap the whole script in the try:...except SystemExit
clause. I fixed that in 10.1, but for 10 you're stuck doing that. Sorry.
Are you sure that shouldn't be
def die():
from sys import exit
try:
exit()
except SystemExit:
pass
raise
Since you are intercepting the exception before the main thread, it might not be causing an exit. You also might want to pass an argument to exit(). Any string would work fine.
-
Thanks, I tried this but raising the error causes the script to "fail" (as it did before I added the try clause). Hmm.bertday– bertday2013年02月26日 20:16:52 +00:00Commented Feb 26, 2013 at 20:16
-
Now that I see Jason's answer, I understand what you were trying to do :)blord-castillo– blord-castillo2013年02月26日 22:12:44 +00:00Commented Feb 26, 2013 at 22:12