Avatar of batmansDad
batmansDadFlag for United States of America asked on

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?
Python

Avatar of undefined
Last Comment
MajorBigDeal

8/22/2022 - Mon
kaufmed

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.
ASKER
batmansDad

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

pepr

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?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
MajorBigDeal

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question