'Process pending timeouts, invoking callbacks for those whose time has
come'

def process_timeouts(self):

    now = time.time()
    to_run = sorted([(k, timer) for (k, timer) in self._timeouts.items() if (timer['deadline'] <= now)], key=(lambda item: item[1]['deadline']))
    for (k, timer) in to_run:
        if (k not in self._timeouts):
            continue
        try:
            timer['callback']()
        finally:
            if (self._timeouts.pop(k, None) is not None):
                self._next_timeout = None
