您的位置:首页 > 其它

pyhton exit

2013-11-01 14:36 239 查看
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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: