views:

34

answers:

1

Example code for the repoze.bfg web framework performs post-response cleanup by adding a __del__ method to an object attached to the request's environ.

Is there a better way to clean up database connections, etc. after the response has been completely sent to the client?

+1  A: 

Since you are dealing with repoze.bfg, best you use their documented way of doing things as it is going to be compatible with their framework and how they manage the request lifecycle. That said, if you want the generic WSGI way of doing it, it is documented in:

http://code.google.com/p/modwsgi/wiki/RegisteringCleanupCode

Graham Dumpleton