Ask coding questions

← Back to all posts
Programmatically exit python repl?
RohanRajagopal (1)

Hello, I just notice that when using sys.exit(0) in a python repl, it says "repl process died unexpectedly". Other than that it works fine, the program stops like it's supposed to, but that message just makes me think that there's a better way to exit a python repl without it "dying unexpectedly"?

Answered by thenullified (159) [earned 5 cycles]
View Answer
Comments
hotnewtop
thenullified (159)

def die():
return ''
can terminate the program if used properly

RohanRajagopal (1)

@starblazer how would that stop it? it would just be a useless function that did nothing

thenullified (159)

when somthing is returned, the function will stop there. if you do somthing like:
def game():
....
....
if lose:
print(you lose!)
return die()
here, game() ends at die()
and die() ends at '' which is nothing and will give you you clean exit
@RohanRajagopal

RohanRajagopal (1)

@starblazer So the only way to exit on repl.it is to wrap the code in a function?

DynamicSquid (4601)

Well how else would you want it to die? Commit blue screen?

RohanRajagopal (1)

@DynamicSquid I just want it to cleanly exit without any messages.