Python os._exit, sys.exit
来源:互联网 发布:医药行业大数据应用 编辑:程序博客网 时间:2024/06/04 18:17
在Python2.7脚本最后 运行语句sys.exit(0)或者运行exit()或者exit(0)的时候会出现结果:SystemExit
exception SystemExit
This exception is raised by the sys.exit() function. When it is not handled, the Python interpreter exits; no stack traceback is printed. If the associated value is a plain integer, it specifies the system exit status (passed to C’s exit() function); if it is None, the exit status is zero; if it has another type (such as a string), the object’s value is printed and the exit status is one.
Instances have an attribute code which is set to the proposed exit status or error message (defaulting to None). Also, this exception derives directly from BaseException and not StandardError, since it is not technically an error.
A call to sys.exit() is translated into an exception so that clean-up handlers (finally clauses of try statements) can be executed, and so that a debugger can execute a script without running the risk of losing control. The os._exit() function can be used if it is absolutely positively necessary to exit immediately (for example, in the child process after a call to fork()).
The exception inherits from BaseException instead of StandardError or Exception so that it is not accidentally caught by code that catches Exception. This allows the exception to properly propagate up and cause the interpreter to exit.
Changed in version 2.5: Changed to inherit from BaseException.
>>> import sys
>>> sys.exit()
if __name__ == "__main__":
output:
try
finally
---------------------
import sys
import os
if __name__ == "__main__":
output:
try
-----------------------
os._exit( n)
Exit to the system with status n, without calling cleanup handlers, flushing stdio buffers, etc. Availability: Macintosh, Unix, Windows.
Note: The standard way to exit is sys.exit(n). _exit() should normally only be used in the child process after a fork().
sys.exit( [arg])
Exit from Python. This is implemented by raising the SystemExit exception, so cleanup actions specified by finally clauses of try statements are honored, and it is possible to intercept the exit attempt at an outer level.
- Python os._exit, sys.exit
- Python os._exit() sys.exit() exit()区别
- Python os._exit() sys.exit() exit()区别
- Python os._exit() sys.exit() exit()区别
- Python os._exit() sys.exit() exit()区别
- python 退出 os._exit(), sys.exit(), exit()
- Python 之 os._exit(), sys.exit()
- python 中 os._exit(), sys.exit(), exit() 的区别是什么?
- os._exit() vs sys.exit()
- os._exit() vs sys.exit()
- Python sys.exit(n) VS os._exit(n)区别
- Python程序退出: os._exit()和sys.exit()
- python中 os._exit() 和 sys.exit(), exit(0)和exit(1) 的用法和区别
- python中 os._exit() 和 sys.exit(), exit(0)和exit(1) 的用法和区别
- python程序退出方式[sys.exit() os._exit() os.kill() os.popen(...)]
- python中sys.exit() os._exit() exit() quit()的简单使用
- python sys.exit()、break、 exit()、quit()、os._exit()、return的区别
- sys.exit(n)和exit()、os._exit(n)
- std string 的常用使用
- vtk获取内存中图像数据
- c#环境变量设置
- undefined reference to `img_convert’的解决方法
- linux & 后台作业
- Python os._exit, sys.exit
- UILabel小结
- DataGridView的单元格内容即时更新方法
- linux下查看文件编码及修改编码
- ubuntu下解压缩zip,tar,tar.gz和tar.bz2文件
- 64位环境下解决apache对中文网址的支持问题
- Hibernate本地SQL查询SQLQuery
- android Listview 软引用SoftReference异步加载图片
- vbs错误对照表