# 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
Comments