The following exception thrown, after using upsert (on ReplicaSetConnection).
Note that the insert succeeds, and also code that follows. So it seems to be indeed happaning, as the exception suggests, during shutdown.
This was seen on 2.1 and above (the exception shown is from the latest commit: f65384284476b6ccd01d2f58f04cfccad87408dc)
Exception in thread ReplicaSetMonitorThread (most likely raised during interpreter shutdown):
Traceback (most recent call last):
File "/usr/lib64/python2.6/threading.py", line 532, in __bootstrap_inner
File "/usr/lib64/python2.6/site-packages/pymongo-2.1.1_-py2.6-linux-x86_64.egg/pymongo/replica_set_connection.py", line 109, in run
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'sleep'