atexit module in embedded Python

Greg Chapman glc at
Tue Feb 11 16:48:07 CET 2003

On Mon, 10 Feb 2003 08:17:07 +0000, "Ricardo B" <etralex at> wrote:

>  anyone here has information about the behavior of the atexit module in
>embedded Python? How does it behave on PyFinalize() and
>Py_EndInterpreter()? Or where the hell can I get some information about

Expanding on Jp's reply, sys.exitfunc (which is what atexit hooks) is not called
by Py_EndInterpreter.  Also, here's a comment from Py_Finalize (in pythonrun.c)
which may (or may not) add something to your understanding (besides what is in
the docs):

	/* The interpreter is still entirely intact at this point, and the
	 * exit funcs may be relying on that.  In particular, if some thread
	 * or exit func is still waiting to do an import, the import machinery
	 * expects Py_IsInitialized() to return true.  So don't say the
	 * interpreter is uninitialized until after the exit funcs have run.
	 * Note that uses an exit func to do a join on all the
	 * threads created thru it, so this also protects pending imports in
	 * the threads created via Threading.

Greg Chapman

More information about the Python-list mailing list