系统退出(0)和操作系统退出(0)之间的区别是什么

2024-04-24 20:19:53 发布

您现在位置:Python中文网/ 问答频道 /正文

请帮助我从功能的不同方面澄清这两个python语句的概念:

  1. sys.exit(0)

  2. os._exit(0)


Tags: 功能概念ossysexit语句
2条回答

os._exit调用C函数_exit(),该函数执行即时程序 终止。请注意“永远不能返回”这句话。

sys.exit()raise SystemExit()相同。它养了一条Python 调用方可能捕获的异常。

原帖:http://bytes.com/topic/python/answers/156121-os-_exit-vs-sys-exit

根据documentation

os._exit():

Exit the process with status n, without calling cleanup handlers, flushing stdio buffers, etc.

Note The standard way to exit is sys.exit(n). _exit() should normally only be used in the child process after a fork().

相关问题 更多 >