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

Provide a way to join background threads when closing a MongoClient

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 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?

            Assignee:
            Unassigned Unassigned
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: