[Python-Dev] Whether to call Py_Finalize when exiting from the child process of a fork from a spawned thread

"Martin v. Löwis" martin at v.loewis.de
Tue Sep 1 20:58:20 CEST 2009

> On one hand, you may not want to call the user's atexit handlers
> multiple times from different processes if they have externally
> visible effects.  On the other hand, people seem to assume that
> Py_Finalize will be called at process exit to do various cleanups.  On
> the third hand, maybe Python could just clear out all the atexit
> handlers in the child after a fork.  So what should the correct
> behavior be?

Standard POSIX fork semantics should be a guidance. IIUC, termination
of the last thread is equivalent to calling exit(0) (although return
from main() still means that exit is invoked right away, and the return
value of main is the exit code - right?). Calling exit means to call
all exit handlers.

So to match POSIX semantics, we should also call the exit handlers in
the child process (along with invoking a final garbage collection etc.)


More information about the Python-Dev mailing list