NixOS/charon — pull request #76 by shlevy (2013-01-31 16:59:30+00:00)
Title: No atexit

This branch replaces usage of atexit with destructors. atexit is a problem for long-running processes (like WebCharon), which currently manually deletes the charon tempdirs that are created (causing a huge number of errors when it exits because the atexit hooks fail). Destructors allow automatic cleanup of resources as soon as they aren't necessary.

This approach does have caveats, however:
* The objects which have `__del__()` defined cannot be part of of a reference cycle. It is OK for them to only be reachable from a cycle (e.g. `a` references `b`, `b` references `a`, `a` references `c`, `c` can have `__del__()`), though. This is avoided by having the `__del__()`-containing classes be very small and do the minimum needed to encapsulate their resource.
* If the objects are reachable at program exit, it is not guaranteed that `__del__()` will be called. This mostly means that if an object is reachable from a module global (bad practice anyway), that global should be explicitly deleted with `del var` before program exit.