What's a safe way to do one-off initialization in Django/mod_wsgi?
Maybe an good old lockfile is a solution for this problem. Not a really elegant solution, but it saves you a lot of headaches in a multithreaded environment.
I'm building a Django app that is designed to be multithreaded but reside in a single process running under mod_wsgi.  At start of day I need to do various, possibly-lengthy, initialization tasks such as loading a cache of data from the database into a quick lookup dict.  I need the intialization to run exactly once before any requests are handled and then to kick off a background thread to periodically update the loaded data.
I've tried putting the initialization code inline in a module but I've found that sometimes (if I put load on the server when it's starting) the init code gets executed more than once, screwing everything up.
Is there a good place to hook into Django or WSGI to run such init code exactly once before any requests are allowed in?  Alternatively, does anyone know under what situations module init code gets executed more than once (particularly in djangp/WSGI-land) or of a good way to stash an "i'm already initialized flag" somewhere?