def poll(self, timeout):
            if timeout > self._prev_timeout:
                # if timeout increased we assume a timer event was handled
                self._idle_done = False
            self._prev_timeout = timeout
            start = time.time()

            # any IO pending wins
            events = self.__poll_obj.poll(0)
            if events:
                self._idle_done = False
                return events

            # our chance to enter idle
            if not self._idle_done:
                for callback in self.__idle_map.values():
                    callback()
                self._idle_done = True

            # then complete the actual request (adjusting timeout)
            timeout = max(0, min(timeout, timeout + start - time.time()))
            events = self.__poll_obj.poll(timeout)
            if events:
                self._idle_done = False
            return events
dataset/ETHPy150Open AnyMesh/anyMesh-Python/example/urwid/main_loop.py/TornadoEventLoop.PollProxy.poll/original