Is sys.exit equivalent to raise SystemExit?

2024/7/7 6:58:28

According to the documentation on sys.exit and SystemExit, it seems that

def sys.exit(return_value=None):  # or return_value=0raise SystemExit(return_value)

is that correct or does sys.exit do something else before?

Answer

According to Python/sysmodule.c, raising SystemExit is all it does.

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://en.xdnf.cn/q/73236.html

Related Q&A

Vertical overflow of table in live display should scroll the content

Im using a Live display to show the content of a Table which grows over time. Eventually there is a vertical overflow and in that case Id like the oldest (i.e. topmost) rows to vanish while the most re…

Reading KML Files Using Fastkml

Ive searched around quite a bit for this specific Python module, and havent been able to find a source which points me in the right direction.Im trying to read a KML file and display all of the feature…

Adding extra fields to django-registration form

I have a model called "Organization" that Ive setup as a User profile and I would like to have the fields from the "Organization" model show up on the registration page. How do I go…

Need to do a daily log rotation (0utc) using Python

Im an admitted noob to Python. Ive written a little logger that takes data from the serial port and writes it to a log file. Ive got a small procedure that opens the file for append, writes, then close…

Save/Load a Dictionary

Ive found a couple of others asking for help with this, but not specifically what Im trying to do. I have a dictionary full of various formats (int, str, bool, etc) and Im trying to save it so I can lo…

py2exe error handling redirection and popup

Been trying to figure out how to get py2exe to handle errors more gracefully. There are basically 2 weird things happening:1) Popup message after shutting down the program => want to suppress (not …

SQL statement for CSV files on IPython notebook

I have a tabledata.csv file and I have been using pandas.read_csv to read or choose specific columns with specific conditions.For instance I use the following code to select all "name" where …

How to draw ellipsoid with plotly

Are there any way to plot a surface like ellipsoid with plotly 3D?Currently only surfaces of the form z=f(x,y) are discussed in the docs. There is also Mesh 3D, but I found no examples for it. It seem…

PyTorch DataLoader uses same random seed for batches run in parallel

There is a bug in PyTorch/Numpy where when loading batches in parallel with a DataLoader (i.e. setting num_workers > 1), the same NumPy random seed is used for each worker, resulting in any random f…

How to fix 502 Bad Gateway Error in production(Nginx)?

When I tried to upload a big csv file of size about 600MB in my project which is hosted in the digital ocean, it tries to upload but shows 502 Bad Gateway Error (Nginx). The application is a data conve…