sys.exit是否等同于引发SystemExit?

Tob*_*ler 5 python exception exit

据有关资料sys.exitSystemExit,似乎

def sys.exit(return_value=None):  # or return_value=0
    raise SystemExit(return_value)
Run Code Online (Sandbox Code Playgroud)

这是正确的还是sys.exit以前做过其他事情?

fal*_*tru 7

据说Python/sysmodule.c,提高SystemExit就是它的全部.

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;
}
Run Code Online (Sandbox Code Playgroud)