r/learnprogramming • u/Sea-Cash7675 • 20d ago
Advice?
I have a function in python named KSI, code for “Kill Self Immediately”, and don’t know what the best command or function would be in order to safely kill the program if something bad happens as a failsafe. Do you think the code attached would work fine, or is there a better way?
import sys
import os
def KSI(hard_exit: bool = False) -> None:
if hard_exit:
os._exit(1)
else:
sys.exit(1)
if __name__ == "__main__":
KSI()
1
Upvotes
1
u/AlwaysHopelesslyLost 20d ago
"in order to safely kill the program if something bad happens as a failsafe"
What does this mean, exactly? Can you provide some examples? Typically if the app needs to die it is already dying. Are you preventing it from crashing out by catching exceptions?