malthe/chameleon — pull request #101 by mitchellrj (2012-03-09 11:57:58+00:00)
Title: Replace atexit temporary file cleanup

Many processes using Chameleon are often daemonized and therefore have to be terminated by signals.

Currently in debug mode, Chameleon creates a temporary directory for each of its template renderings which is then cleaned up with an 'atexit' handler. The documentation for the 'atexit'[1] module makes it clear that these handlers are not called when "the program is killed by a signal not handled by Python" - the inference being that the signal must be handled by Python itself, not any use of the 'signal' module, and indeed this is the case where daemonized python processes are killed correctly by SIGKILL.

This is particularly problematic when Chameleon is set to render in debug mode repeatedly, as it can cause a build up of temporary files which are not cleared during long running processes[2].

1. http://docs.python.org/library/atexit.html
2. http://awesomeco.de/blog/pastescript-deform-chameleon-and-a-whole-load-of-temporary-files/