It was the intention that all modules would be purged of their data
and then deleted (doneimport() in Python/import.c). However if you
turn on threads at compile time it will never work since doneimport()
is then not called -- there is the (remote) possibility that another
thread may still be active when the main thread exits so the purging
of all modules would be unsafe in this case.
> If there are some other ways to detect termination of program, I'd
> like to hear from you.
If you assign a function pointer to sys.exitfunc, it will be called
when the program terminates. Note that the system supports only a
single function here -- but it is trivial to implement a
"cleanup-registry" module in Python using this functionality.
--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>