Link to home
Start Free TrialLog in
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?
Avatar of kaufmed
kaufmed
Flag of United States of America image

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.
Avatar of batmansDad

ASKER

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

Avatar of pepr
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?
ASKER CERTIFIED SOLUTION
Avatar of MajorBigDeal
MajorBigDeal
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial