I would like to know if there is a way of programatically stopping a python script execution without killing the process like we do with this code:
Define your own exception,
class HaltException(Exception): pass
and wrap the script in
try: # script goes here # when you want to stop, raise HaltException("Somebody stop me!") except HaltException as h: print(h) # now what?