def __init__(self): self.selectables = set() self.reading = set() self.writing = set() self.waiter = selectable_waiter() self.reading.add(self.waiter) self.stopped = False self.thread = None
def wait(self, timeout=None): assert self.lock._is_owned() if not self.waiters: self.waiters.append(compat.selectable_waiter()) sw = self.waiters.pop(0) self.waiting.append(sw) try: st = self.lock._release_save() sw.wait(timeout) finally: self.lock._acquire_restore(st) self.waiting.remove(sw) self.waiters.append(sw)