Acquire a read lock for the current thread, waiting at most
        timeout seconds or doing a non-blocking check in case timeout
        is <= 0.

        In case timeout is None, the call to acquire_read blocks until
        the lock request can be serviced.

        If the lock has been successfully acquired, this function
        returns True, on a timeout it returns None.

def acquire_read(self, timeout=None):
        """
        Acquire a read lock for the current thread, waiting at most
        timeout seconds or doing a non-blocking check in case timeout
        is <= 0.

        In case timeout is None, the call to acquire_read blocks until
        the lock request can be serviced.

        If the lock has been successfully acquired, this function
        returns True, on a timeout it returns None.
        """
        if timeout is not None:
            endtime = time.time() + timeout
        me = threading.currentThread()
        self.__condition.acquire()
        try:
            if self.__writer is me:
                self.__writer_lock_count += 1
                return True
            while True:
                if self.__writer is None:
                    if self.__pending_writers:
                        if me in self.__readers:
                            # Grant the lock anyway if we already
                            # hold one, because this would otherwise
                            # cause a deadlock between the pending
                            # writers and ourself.
                            self.__readers[me] += 1
                            return True
                        # else: does nothing, will wait below
                        # writers are given priority
                    else:
                        self.__readers[me] = self.__readers.get(me, 0) + 1
                        return True
                if timeout is not None:
                    remaining = endtime - time.time()
                    if remaining <= 0:
                        return None
                    self.__condition.wait(remaining)
                else:
                    self.__condition.wait()
        finally:
            self.__condition.release()