print('ignored 'bye sys world ignored trylater(finallyprint('cleanup'bye sys world cleanup :\pp \system\exitsinteractive session process exits os module exits it' possible to exit python in other waystoo for instancewithin forked child process on unixwe typically call the os _exit function rather than sys exitthreads may exit with _thread exit calland tkinter gui applications often end by calling something named tk(quit(we'll meet the tkinter module later in this booklet' take look at os exits here on os _exitthe calling process exits immediately instead of raising an exception that could be trapped and ignored in factthe process also exits without flushing output stream buffers or running cleanup handlers (defined by the atexit standard library module)so this generally should be used only by child processes after forkwhere overall program shutdown actions aren' desired example - illustrates the basics example - pp \system\exits\testexit_os py def outahere()import os print('bye os world'os _exit( print('never reached'if __name__ ='__main__'outahere(unlike sys exitos _exit is immune to both try/except and try/finally interceptionc:\pp \system\exitspython testexit_os py bye os world :\pp \system\exitspython from testexit_os import outahere tryoutahere(exceptprint('ignored'bye os world exits interactive process :\pp \system\exitspython program exits