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

Remove threading.Lock() from SocketChecker

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.11
    • Affects Version/s: None
    • Component/s: Internal
    • Labels:
      None

      We can remove the threading.Lock() added to SocketChecker in PYTHON-1189 by giving each a connection its own SocketChecker() instance. Creating a SocketChecker is cheap so there should be no reason to use a single instance per pool.

      Another small improvement we can make is to remove the Pool.lock acquisition when popping a socket. deque.popleft() is already thread-safe so there is no reason to hold the lock here

                          with self.lock:
                              sock_info = self.sockets.popleft()
      

      Edit: Upon further thought, let's not remove the lock when popping a socket. Doing so would require changes to other sections of the Pool class which assume that sockets does not change when holding the lock.

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

              Created:
              Updated:
              Resolved: