Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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, passes, and keeps on trucking right to the end of the script. Is there any way to actually make the script stop?

share|improve this question
add comment

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
    
Thanks Jason! Good to know :) –  Mapbert Feb 26 '13 at 21:05
add comment

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.

share|improve this answer
    
Thanks, I tried this but raising the error causes the script to "fail" (as it did before I added the try clause). Hmm. –  Mapbert Feb 26 '13 at 20:16
    
Now that I see Jason's answer, I understand what you were trying to do :) –  blord-castillo Feb 26 '13 at 22:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.