Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-3193

Add ResourceWarning for unclosed MongoClients in __del__

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • 4.8
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            steve.silvester@mongodb.com Steve Silvester
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: