-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
MongoClient.close() closes its sockets and signals its background threads to exit but it does not actually wait for the threads to exit (via join). This is problematic when using a MongoClient from a subinterpreter. Even when closing the MongoClient, an error gets raised when closing the subinterpreter: Py_EndInterpreter: not the last thread
Reported in: https://groups.google.com/d/msg/mongodb-user/vgsE6MpcyGE/1xm-WXMrAAAJ
and: https://groups.google.com/forum/#!topic/jep-project/lAv7-HVAnv8
Things to consider:
- Is the lack of a join() intentional?
- Don't hold the topology lock when attempting a join because the thread can be waiting for the same lock.
- PeriodicExecutor used to sleep for 100ms at a time to and check for a close but that was changed in
PYTHON-983. Now PeriodicExecutors sleep for half a second at a time. Perhaps we should reintroduce the 100ms sleeps (without using condition variables on Python 2). - Should we add a timeout parameter to MongoClient.close?
- Should we provide a MongoClient.join method with a timeout?
- is related to
-
PYTHON-1896 MongoClient hangs for 0.5 seconds on script exit
- Closed
-
PYTHON-3174 Remove noisy Topology has THREADS RUNNING check for main test client
- Closed