pyhton exit

exit("0") is normally out, and means "successful termination"

exit("1") is abnormal, and means "abnormal termination”. Most systems require it to be in the range 0-127.

sys.exit("some error message") is a quick way to exit a program when an error occurs.

 

Since exit() ultimately “only” raises an exception, it will only exit the process when called from the main thread, and the exception is not intercepted.

 

import sys, traceback

def main():

     try:

         do main program stuff here

            ....

        except KeyboardInterrupt:

            print "Shutdown requested...exiting"

        except Exception:

           traceback.print_exc(file=sys.stdout)

           sys.exit(0)

if __name__ == "__main__":

     main()

原文地址:https://www.cnblogs.com/cl1024cl/p/6205590.html