Is sys.exit equivalent to raise SystemExit?
根据有关
1 2 | def sys.exit(return_value=None): # or return_value=0 raise SystemExit(return_value) |
这是正确的还是江户十一〔0〕以前做过别的事?
根据
1 2 3 4 5 6 7 8 9 10 | static PyObject * sys_exit(PyObject *self, PyObject *args) { PyObject *exit_code = 0; if (!PyArg_UnpackTuple(args,"exit", 0, 1, &exit_code)) return NULL; /* Raise SystemExit so callers may catch it or clean up. */ PyErr_SetObject(PyExc_SystemExit, exit_code); return NULL; } |
是的,提升
如您在源代码https://github.com/python git/python/blob/715a6e5035b21ac493827706ec4c630d6e960/python/sysmodule.c中所见。
1 2 3 4 5 6 7 8 9 10 | static PyObject * sys_exit(PyObject *self, PyObject *args) { PyObject *exit_code = 0; if (!PyArg_UnpackTuple(args,"exit", 0, 1, &exit_code)) return NULL; /* Raise SystemExit so callers may catch it or clean up. */ PyErr_SetObject(PyExc_SystemExit, exit_code); return NULL; } |
它只提高系统退出,不做任何其他事情