@djangoproject · Post #159 · 09/12/2016, 05:37 PM
https://docs.python.org/3/library/atexit.html The #atexit module defines #functions to #register and #unregister cleanup functions. Functions thus registered are automatically executed upon normal interpreter termination. atexit runs these functions in the reverse order in which they were registered; if you register A, B, and C, at #interpreter#termination time they will be run in the order C, B, A.