I thought Python Processes call their atexit functions when they terminate. Note that I'm using Python 2.7. Here is a simple example:
from __future__ import print_function
import atexit
from multiprocessing import Process
def test():
atexit.register(lambda: print("atexit function ran"))
process = Process(target=test)
process.start()
process.join()
I'd expect this to print "atexit function ran" but it does not.
Note that this question: Python process won't call atexit is similar, but it involves Processes that are terminated with a signal, and the answer involves intercepting that signal. The Processes in this question are exiting gracefully, so (as far as I can tell anyway) that question & answer do not apply (unless these Processes are exiting due to a signal somehow?).
terminate(). I've deleted the duplication comment. Perhaps you can set up a signal handler and try to find out if there are any signals sent?multiprocessing.util.Finalizeclass, see the blog post for details: Guaranteed Finalization Without Context Manager.set_start_method('spawn'), as this problem only happens when forking. These workarounds probably won't be necessary anymore though, as it seems that Python 3.13 will fix this problem with forked processes: github.com/python/cpython/pull/114279