def remove_alarm(self, handle): """ Remove an alarm. Returns True if the alarm exists, False otherwise """ return scheduler.get_scheduler().remove(handle)
def __init__(self, fo=None, prompt="$", timeout=90.0, logfile=None, engine=None): if hasattr(fo, "fileno"): self._fo = fo try: # for Process objects. This needs to catch EINTR for timeouts. self._fo.restart(0) except AttributeError: pass else: raise ValueError("Expect: first parameter not a file-like object.") self.default_timeout = timeout self._log = logfile self.cmd_interp = None self._prompt = prompt.encode() self._patt_cache = {} self._buf = '' self.eof = 0 self.sched = scheduler.get_scheduler() self._engine = engine # If a match on a list occurs, the index in the list # search on the last 'expect' method call is saved here. self.expectindex = -1
def alarm(self, seconds, callback): """ Call callback() given time from from now. No parameters are passed to callback. Returns a handle that may be passed to remove_alarm() seconds -- floating point time to wait before calling callback callback -- function to call from event loop """ return scheduler.get_scheduler().add(callback, seconds)
def test_basic_scheduler(self): sched = scheduler.get_scheduler() start = now() sched.add(self._tp, 2, args=(2, start)) sched.add(self._tp, 4, args=(4, start)) sched.add(self._tp, 5, args=(5, start)) sched.add(self._tp, 6, args=(6, start)) sched.add(self._tp, 7, args=(7, start)) print("sleeping for 8 seconds") sched.sleep(8) self.assertAlmostEqual(now() - start, 8.0, places=2) scheduler.del_scheduler()
def loop(self, poller, timeout=-1.0, callback=NULL): while self._procs: poller.poll(timeout) callback(self) if scheduler.get_scheduler(): # wait for any restarts scheduler.sleep(1.5)