async def get(self, timeout=None): "waits for and returns the next available Event. Waits forever if" \ " necessary if timeout is None; else it is the number of seconds" \ " (fractions allowed) to wait; if no event becomes available during" \ " that time, None is returned." awaiting = None def timedout(w_awaiting): awaiting = w_awaiting() if awaiting != None and not awaiting.done(): awaiting.set_result(False) #end if #end timedout #begin get loop = self._loop() assert loop != None, "loop has gone away" while True: if len(self._notifs) != 0: result = self._notifs.pop(0) break #end if awaiting = loop.create_future() timeout_task = None if timeout != None: if timeout <= 0: result = None break #end if timeout_task = loop.call_later(timeout, timedout, weak_ref(awaiting)) #end if self._awaiting.append(awaiting) if self._reader_count == 0: self._add_remove_watch(True) #end if self._reader_count += 1 got_one = await awaiting self._reader_count -= 1 if self._reader_count == 0: self._add_remove_watch(False) #end if if timeout_task != None: timeout_task.cancel() #end if try: self._awaiting.pop(self._awaiting.index(awaiting)) except ValueError: pass #end try if not got_one: result = None break #end if #end while return \ result
def __init__(self, server: Server, sleep: Union[int, float]) -> None: # pragma: no cover from threading import Event super().__init__(daemon=True) self._server_wr = weak_ref(server) self._sleep = sleep self._stop_event = Event() self._run_lock = Lock()
def test_object_bound_method_deleted(self) -> None: # arrange obj = _C() obj_wr = weak_ref(obj) # act self.crawler.set_is_image_addable(obj.m_b) self.assertEqual(self.crawler.get_is_image_addable(), obj.m_b) del obj # assert self.assertIsNone(obj_wr(), 'obj is intended to be deleted') self.assertIsNone(self.crawler.get_is_image_addable())
def __new__(celf, _wd, _parent): self = celf._instances.get((_wd, _parent._fd)) if self == None: self = super().__new__(celf) self._wd = _wd self._parent = weak_ref(_parent) celf._instances[(_wd, _parent._fd)] = self #end if # pathname, mask set by parent _parent._watches[_wd] = self return \ self
def create(celf, flags=0, loop=None): "creates a new Watcher for collecting filesystem notifications. loop is the" \ " asyncio event loop into which to install reader callbacks; the default" \ " loop is used if this not specified." if loop == None: loop = asyncio.get_event_loop() #end if fd = libc.inotify_init1(flags) if fd < 0: errno = ct.get_errno() raise OSError(errno, os.strerror(errno)) #end if result = celf(fd) if result._loop == None: result._loop = weak_ref(loop) elif result._loop() != loop: raise RuntimeError("watcher was not created on current event loop") #end if return \ result