Skip to content
Sign upLog in
← Back to Community

Programmatically exit python repl?

Profile icon
RohanRajagopal

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 [earned 5 cycles]
View Answer
Voters
Profile icon
eamonwong4
Profile icon
RohanRajagopal
Comments
hotnewtop
Profile icon
thenullified

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

Profile icon
RohanRajagopal

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

Profile icon
thenullified

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

Profile icon
RohanRajagopal

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

Profile icon
thenullified

something like [email protected]

Profile icon
DynamicSquid

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

Profile icon
SpaceFire

@DynamicSquid
PySuicide Library

Profile icon
RohanRajagopal

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

Profile icon
Rache

@RohanRajagopal
Hi Rohan, did you find your answer? I've tackled the same issue and am not satisfied yet with the options I got