-
Type: Improvement
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
Completed
-
Currently if the user does not explicitly close() the client, most resources cleaned up when the client is garbage collected but some resources, like sessions, will not be cleaned up efficiently (since the endSessions command doesn't have a chance to run). We think this might be the source of intermittent failures in tests.
We should look into adding a MongoClient._del_ method that checks whether the client has been closed. If it is not closed, issue a warning and clean up resources.
pyzeromq uses a similar method.
We had some concerns that using _del_ might cause a reference cycle, but the CPython docs say that "the cycle will be later detected and deleted by the cyclic garbage collector."
If we are adopting this model, we should also use warning control in our test suite to catch these warnings.
- causes
-
PYTHON-4907 MongoClient del raises TypeError: 'NoneType' object is not callable
- Ready for Work
-
PYTHON-4758 MongoClient with connect=False still generates a resource warning
- Closed
- has to be done after
-
PYTHON-3606 Document best practice for closing MongoClients and cursors
- Backlog
- related to
-
PYTHON-3229 Document that client.close cannot be called from __del__
- Backlog