code: def lock(cls, pid, connection, session):
          
          with cls._lock:
              cls._ensure_pool_exists(pid)
              cls._pools[pid].lock(connection, session)
docs: Explicitly lock the specified connection in the pool
  
          :param str pid: The pool id
          :type connection: psycopg2.extensions.connection
          :param connection: The connection to add to the pool
          :param queries.Session session: The session to hold the lock