title: Django pre-shutdown hook to close hanging pymongo connection
body: <p>I'm using pymongo in a Django project, and recently I've began to run into a problem where, upon exiting the main Django process (even through a management command) the pymongo connection will hang, and the process will never exit. Obviously, there's something wrong somewhere in the stack, but for now the best solution seems to be to explicitly close the connection before Django exits. </p>
  
  <p>So: is there a pre-shutdown signal or hook that Django provides for this?</p>
  
  <p>BTW: my connection code in case you're interested.</p>
  
  <pre><code>from django.conf import settings
  from pymongo import ReplicaSetConnection, ReadPreference
  
  conn = ReplicaSetConnection(
      hosts_or_uri=settings.MONGO['HOST'],
      replicaSet=settings.MONGO['REPLICASET'],
      safe=settings.MONGO.get('SAFE', False),
      journal=settings.MONGO.get('JOURNAL', False),
      read_preference=ReadPreference.PRIMARY
  )
  
  db = getattr(conn, settings.MONGO['DB'])
  </code></pre>
  
  <p>(and as a point of curiousity, is this the right way to do connection pooling in pymongo?)</p>