def close_db_connections(func, *args, **kwargs):
 def _close_db_connections(*args, **kwargs):
  ret = None
  try:
   ret = func(*args, **kwargs)
  finally:
   from django.db import connections
   for conn in connections.all():
    conn.close()
  return ret
 return _close_db_connections

def close_db_connections ( func , * args , ** kwargs ) : def _close_db_connections ( * args , ** kwargs ) : ret = None try : ret = func ( * args , ** kwargs ) finally : from django . db import connections for conn in connections . all ( ) : conn . close ( ) return ret return _close_db_connections
decorator to explicitly close db connections during threaded execution note this is necessary to work around: URL .