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

Provide a way to join background threads when closing a MongoClient

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Backlog
    • Major - P3
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      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?

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated: