Make runfcgi fail when database connection is open before fork

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# monkey-patch flup to fail loudly if database connection is open when
# preforked child starts - but ONLY when debug=true, so that we don't
# use monkey-patch on production.
import sys
if 'runfcgi' in sys.argv and 'debug=true' in sys.argv:
    from flup.server.preforkserver import PreforkServer
    def _spawnChild(self, sock):
        from django.db import connection
        if connection.connection is not None:
            raise Exception('''Django database connection is open. This MAY NOT happen.''')
        return self._spawnChild_orig(sock)
    PreforkServer._spawnChild_orig = PreforkServer._spawnChild
    PreforkServer._spawnChild = _spawnChild

More like this

  1. Alternative to Class Based Views by sleepycal 9 months, 1 week ago
  2. Form widget for text inputs with external link. version2 by ramusus 4 years ago
  3. Auto-create Django admin user during syncdb by statico 3 years, 5 months ago
  4. Persistent connection to PostgreSQL database by mike_tk 3 years, 9 months ago
  5. Effective content caching for mass-load site using redirect feature by nnseva 1 year, 11 months ago

Comments

(Forgotten your password?)