Exit(0) not being called

Hi All

I have the following python code:

    array1= []   
    for i in range(0,int(5),1):
        if (i < 6 ):
            log("Do Something with Entry")
    
    try:
        log("Do Something 1")
    except KeyboardInterrupt:
        log("ERROR')
    
    try:
        log("Do Something 2")
    except KeyboardInterrupt:
        log("ERROR')


except :
    print 'ERROR'
    
sys.exit(0)

Open in new window


The problem that I am having is that

log("Do Something 2") gets logged but the sys.exit(0) is never called, if I move this into the try it complains that it is not at the right level and gave an error message.

Is there something obvious that I am missing?
batmansDadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Is you indentation off? I can't tell from what you posted, but the sys.exit(0) call along with the general except (i.e. the non-specific exception) appears to be at a different level than the inner try/except.
0
batmansDadAuthor Commented:
Sorry I missed a try in my post (the code has this)

    
try:
    array1= []   
    for i in range(0,int(5),1):
        if (i < 6 ):
            log("Do Something with Entry")
    
    try:
        log("Do Something 1")
    except KeyboardInterrupt:
        log("ERROR')
    
    try:
        log("Do Something 2")
    except KeyboardInterrupt:
        log("ERROR')


except :
    print 'ERROR'
    
sys.exit(0)

Open in new window

0
peprCommented:
if I move this into the try it complains that it is not at the right level and gave an error message.
As kaufmed wrote, the problem could be with indentation of the moved command. Indentation matters in Python. When you move the command below the log("Do Something 2"), you have to give it the same indentation.

Beware of mixing tabs and spaces. It is recommended to use 4 spaces for each indentation level.

My question towards you is... What do you expect from calling sys.exit(0)? How do you know it is not called? What your log contains as the last messages?
0
MajorBigDealCommented:
instead of using  sys.exit(0), can you just use quit()
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.