-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: 4.9, 4.10
-
Component/s: None
-
None
-
Python Drivers
-
Not Needed
MongoClient del can raise TypeError: 'NoneType' object is not callable at interpreter shutdown:
$ python Python 3.13.0 (v3.13.0:60403a5409f, Oct 7 2024, 00:37:40) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> client = MongoClient() >>> exit() Exception ignored in: <function MongoClient.__del__ at 0x127bf02c0> Traceback (most recent call last): File "/Users/shane/git/mongo-python-driver/pymongo/synchronous/mongo_client.py", line 1192, in __del__ TypeError: 'NoneType' object is not callable
At interpreter shutdown global variables can be set to None so we have to guard against this case:
warn = warning.warn cls = ResourceWarning if self._opened and not self._closed and warn and cls: warn( ( f"Unclosed {type(self).__name__} opened at:\n{self._topology_settings._stack}" f"Call {self.__class__.__name__}.close() to safely shut down your client and free up resources." ), cls, stacklevel=2, )
- is caused by
-
PYTHON-3193 Add ResourceWarning for unclosed MongoClients in __del__
- Closed