Python sched.scheduler() Examples
The following are 30
code examples of sched.scheduler().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sched
, or try the search function
.
Example #1
Source File: tensorflow_profiler.py From benchmarks with Apache License 2.0 | 6 votes |
def start(self): """Schedule start/stop profiler event specified in profiler_enabled_time_str.""" if not self.profiler_enabled_time_str: return last_end_time = -1 for time_str in self.profiler_enabled_time_str.split(','): begin_time = int(time_str.split(':')[0].strip()) end_time_str = time_str.split(':')[1].strip() if ':' in time_str else None end_time = int(end_time_str) if end_time_str else 365 * 24 * 60 * 60 if begin_time <= last_end_time: raise ValueError('begin_time {} is no larger than the last ' 'end_time {}'.format(begin_time, last_end_time)) if end_time <= begin_time: raise ValueError('end_time {} is no larger than begin_time {}'.format( end_time, begin_time)) # 4th positional arg added to support Python2 for the short-term. self.scheduler.enter(begin_time, 1, _start_profiler, ()) # pylint: disable=no-value-for-parameter self.scheduler.enter(end_time, 1, _stop_and_save_profiler, argument=(self.output_dir,)) last_end_time = end_time threading.Thread(target=self.scheduler.run).start()
Example #2
Source File: tensorflow_profiler.py From benchmarks with Apache License 2.0 | 6 votes |
def stop(self): """Stop scheduler and save profiler data if any event is cancelled.""" event_canceled = False for event in self.scheduler.queue: try: self.scheduler.cancel(event) event_canceled = True except ValueError: # This is OK because the event may have been just canceled pass # Signal the scheduler thread to stop sleeping self.exit_event.set() # Save the profiler data if any event is canceled if event_canceled: _stop_and_save_profiler(self.output_dir)
Example #3
Source File: scheduler.py From grimoirelab-kingarthur with GNU General Public License v3.0 | 6 votes |
def _cancel_task(self, task_id): event = self._tasks_events.get(task_id, None) # The job is in the scheduler if event: try: self._delayer.cancel(event) del self._tasks_events[task_id] logger.debug("Event found for task %s; canceling it", task_id) return except ValueError: logger.debug("Event not found for task %s; it should be on the queue", task_id) # The job is running on a queue job_id = self._tasks_jobs[task_id] rq.cancel_job(job_id, connection=self.conn) logger.debug("Job #%s canceled", job_id) del self._tasks_jobs[task_id]
Example #4
Source File: scheduler.py From grimoirelab-kingarthur with GNU General Public License v3.0 | 6 votes |
def __init__(self, registry, conn, queues, polling=SCHED_POLLING, async_mode=True): super().__init__() self.registry = registry self.conn = conn self.polling = polling self.async_mode = async_mode self._rwlock = RWLock() self._delayer = sched.scheduler() self._queues = { queue_id: rq.Queue(queue_id, connection=self.conn, is_async=self.async_mode) # noqa: W606 for queue_id in queues } self._tasks_events = {} self._tasks_jobs = {}
Example #5
Source File: updater.py From dnfdragora with GNU General Public License v3.0 | 6 votes |
def __reschedule_update_in(self, minutes): ''' clean up scheduler and schedule update in 'minutes' ''' logger.debug("rescheduling") if not self.__scheduler.empty(): logger.debug("Reset scheduler") for task in self.__scheduler.queue: try: self.__scheduler.cancel(task) except: pass if self.__scheduler.empty(): self.__scheduler.enter(minutes * 60, 1, self.__get_updates) logger.info("Scheduled check for updates in %d %s", minutes if minutes >= 1 else minutes*60, "minutes" if minutes >= 1 else "seconds" ) return True return False
Example #6
Source File: dashview.py From ccs-calendarserver with Apache License 2.0 | 6 votes |
def __init__(self, server, logfile, screen): self.screen = screen self.paused = False self.seconds = 1.0 self.sched = sched.scheduler(time.time, time.sleep) self.aggregate = False self.selected_server = Point() self.server_window = None if server: self.client = DashboardClient(self, server) self.mode = self.MODE_SERVER else: self.client = DashboardLogfile(self, logfile) self.mode = self.MODE_LOGREPLAY self.client_error = False
Example #7
Source File: test_sched.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_empty(self): l = [] fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) self.assertTrue(scheduler.empty()) for x in [0.05, 0.04, 0.03, 0.02, 0.01]: z = scheduler.enterabs(x, 1, fun, (x,)) self.assertFalse(scheduler.empty()) scheduler.run() self.assertTrue(scheduler.empty())
Example #8
Source File: test_sched.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_enter_concurrent(self): q = queue.Queue() fun = q.put timer = Timer() scheduler = sched.scheduler(timer.time, timer.sleep) scheduler.enter(1, 1, fun, (1,)) scheduler.enter(3, 1, fun, (3,)) t = threading.Thread(target=scheduler.run) t.start() timer.advance(1) self.assertEqual(q.get(timeout=TIMEOUT), 1) self.assertTrue(q.empty()) for x in [4, 5, 2]: z = scheduler.enter(x - 1, 1, fun, (x,)) timer.advance(2) self.assertEqual(q.get(timeout=TIMEOUT), 2) self.assertEqual(q.get(timeout=TIMEOUT), 3) self.assertTrue(q.empty()) timer.advance(1) self.assertEqual(q.get(timeout=TIMEOUT), 4) self.assertTrue(q.empty()) timer.advance(1) self.assertEqual(q.get(timeout=TIMEOUT), 5) self.assertTrue(q.empty()) timer.advance(1000) t.join(timeout=TIMEOUT) self.assertFalse(t.is_alive()) self.assertTrue(q.empty()) self.assertEqual(timer.time(), 5)
Example #9
Source File: test_sched.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_queue(self): l = [] fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) now = time.time() e5 = scheduler.enterabs(now + 0.05, 1, fun) e1 = scheduler.enterabs(now + 0.01, 1, fun) e2 = scheduler.enterabs(now + 0.02, 1, fun) e4 = scheduler.enterabs(now + 0.04, 1, fun) e3 = scheduler.enterabs(now + 0.03, 1, fun) # queue property is supposed to return an order list of # upcoming events self.assertEqual(scheduler.queue, [e1, e2, e3, e4, e5])
Example #10
Source File: net_udp_core.py From openschc with MIT License | 5 votes |
def _actual_init(self): self.sd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.sd.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.sd.bind(self.udp_src) scheduler = self.protocol.get_system().get_scheduler() scheduler.add_fd_callback(self.sd.fileno(), self.event_packet_received, ())
Example #11
Source File: dashcollect.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
def __init__(self, config, logdir, loghourly, compress_log): self.logdir = logdir self.loghourly = loghourly self.compress_log = compress_log self.title = config.title self.pods = config.pods self.sched = sched.scheduler(time.time, time.sleep) self.seconds = 1 self.lastData = {} self._stop = False
Example #12
Source File: workrate.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
def __init__(self, server): self.paused = False self.seconds = 1.0 self.sched = sched.scheduler(time.time, time.sleep) self.client = MonitorClient(server) self.client.addItem("test_work") self.last_queued = None self.last_completed = None self.last_time = None
Example #13
Source File: workrate.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
def run(self): """ Create the initial window and run the L{scheduler}. """ self.sched.enter(self.seconds, 0, self.updateResults, ()) self.sched.run()
Example #14
Source File: net_udp_core.py From openschc with MIT License | 5 votes |
def send_later(self, delay, udp_dst, packet): assert self.protocol is not None scheduler = self.protocol.get_system().get_scheduler() scheduler.add_event(delay, self._send_now, (udp_dst, packet))
Example #15
Source File: net_udp_core.py From openschc with MIT License | 5 votes |
def _sleep(self, delay): """Implements a delayfunc for sched.scheduler This delayfunc sleeps for `delay` seconds at most (in real-time, but if any event appears in the fd_table (e.g. packet arrival), the associated callbacks are called and the wait is stop. """ self.wait_one_callback_until(delay)
Example #16
Source File: net_udp_core.py From openschc with MIT License | 5 votes |
def __init__(self): self.scheduler = SelectScheduler()
Example #17
Source File: dashview.py From ccs-calendarserver with Apache License 2.0 | 5 votes |
def run(self): """ Create the initial window and run the L{scheduler}. """ self.windows = [] self.client.update() self.displayWindow(None) self.sched.enter(self.seconds, 0, self.updateDisplay, ()) self.sched.run()
Example #18
Source File: test_sched.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_cancel(self): l = [] fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) now = time.time() event1 = scheduler.enterabs(now + 0.01, 1, fun, (0.01,)) event2 = scheduler.enterabs(now + 0.02, 1, fun, (0.02,)) event3 = scheduler.enterabs(now + 0.03, 1, fun, (0.03,)) event4 = scheduler.enterabs(now + 0.04, 1, fun, (0.04,)) event5 = scheduler.enterabs(now + 0.05, 1, fun, (0.05,)) scheduler.cancel(event1) scheduler.cancel(event5) scheduler.run() self.assertEqual(l, [0.02, 0.03, 0.04])
Example #19
Source File: test_sched.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_priority(self): l = [] fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) for priority in [1, 2, 3, 4, 5]: z = scheduler.enterabs(0.01, priority, fun, (priority,)) scheduler.run() self.assertEqual(l, [1, 2, 3, 4, 5])
Example #20
Source File: test_sched.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_enterabs(self): l = [] fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) for x in [0.05, 0.04, 0.03, 0.02, 0.01]: z = scheduler.enterabs(x, 1, fun, (x,)) scheduler.run() self.assertEqual(l, [0.01, 0.02, 0.03, 0.04, 0.05])
Example #21
Source File: test_sched.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_enterabs(self): l = [] fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) for x in [0.05, 0.04, 0.03, 0.02, 0.01]: z = scheduler.enterabs(x, 1, fun, (x,)) scheduler.run() self.assertEqual(l, [0.01, 0.02, 0.03, 0.04, 0.05])
Example #22
Source File: test_sched.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_enter(self): l = [] fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) for x in [0.5, 0.4, 0.3, 0.2, 0.1]: z = scheduler.enter(x, 1, fun, (x,)) scheduler.run() self.assertEqual(l, [0.1, 0.2, 0.3, 0.4, 0.5])
Example #23
Source File: test_sched.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_run_non_blocking(self): l = [] fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) for x in [10, 9, 8, 7, 6]: scheduler.enter(x, 1, fun, (x,)) scheduler.run(blocking=False) self.assertEqual(l, [])
Example #24
Source File: test_sched.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_args_kwargs(self): flag = [] def fun(*a, **b): flag.append(None) self.assertEqual(a, (1,2,3)) self.assertEqual(b, {"foo":1}) scheduler = sched.scheduler(time.time, time.sleep) z = scheduler.enterabs(0.01, 1, fun, argument=(1,2,3), kwargs={"foo":1}) scheduler.run() self.assertEqual(flag, [None])
Example #25
Source File: test_sched.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_queue(self): l = [] fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) now = time.time() e5 = scheduler.enterabs(now + 0.05, 1, fun) e1 = scheduler.enterabs(now + 0.01, 1, fun) e2 = scheduler.enterabs(now + 0.02, 1, fun) e4 = scheduler.enterabs(now + 0.04, 1, fun) e3 = scheduler.enterabs(now + 0.03, 1, fun) # queue property is supposed to return an order list of # upcoming events self.assertEqual(scheduler.queue, [e1, e2, e3, e4, e5])
Example #26
Source File: test_sched.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_empty(self): l = [] fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) self.assertTrue(scheduler.empty()) for x in [0.05, 0.04, 0.03, 0.02, 0.01]: z = scheduler.enterabs(x, 1, fun, (x,)) self.assertFalse(scheduler.empty()) scheduler.run() self.assertTrue(scheduler.empty())
Example #27
Source File: test_sched.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_cancel(self): l = [] fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) now = time.time() event1 = scheduler.enterabs(now + 0.01, 1, fun, (0.01,)) event2 = scheduler.enterabs(now + 0.02, 1, fun, (0.02,)) event3 = scheduler.enterabs(now + 0.03, 1, fun, (0.03,)) event4 = scheduler.enterabs(now + 0.04, 1, fun, (0.04,)) event5 = scheduler.enterabs(now + 0.05, 1, fun, (0.05,)) scheduler.cancel(event1) scheduler.cancel(event5) scheduler.run() self.assertEqual(l, [0.02, 0.03, 0.04])
Example #28
Source File: test_sched.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_priority(self): l = [] fun = lambda x: l.append(x) scheduler = sched.scheduler(time.time, time.sleep) for priority in [1, 2, 3, 4, 5]: z = scheduler.enterabs(0.01, priority, fun, (priority,)) scheduler.run() self.assertEqual(l, [1, 2, 3, 4, 5])
Example #29
Source File: test_sched.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_enter_concurrent(self): q = queue.Queue() fun = q.put timer = Timer() scheduler = sched.scheduler(timer.time, timer.sleep) scheduler.enter(1, 1, fun, (1,)) scheduler.enter(3, 1, fun, (3,)) t = threading.Thread(target=scheduler.run) t.start() timer.advance(1) self.assertEqual(q.get(timeout=TIMEOUT), 1) self.assertTrue(q.empty()) for x in [4, 5, 2]: z = scheduler.enter(x - 1, 1, fun, (x,)) timer.advance(2) self.assertEqual(q.get(timeout=TIMEOUT), 2) self.assertEqual(q.get(timeout=TIMEOUT), 3) self.assertTrue(q.empty()) timer.advance(1) self.assertEqual(q.get(timeout=TIMEOUT), 4) self.assertTrue(q.empty()) timer.advance(1) self.assertEqual(q.get(timeout=TIMEOUT), 5) self.assertTrue(q.empty()) timer.advance(1000) t.join(timeout=TIMEOUT) self.assertFalse(t.is_alive()) self.assertTrue(q.empty()) self.assertEqual(timer.time(), 5)
Example #30
Source File: time_scheduler.py From tandem with Apache License 2.0 | 5 votes |
def start(self): """ Starts this scheduler. Until this is called, no tasks will actually be scheduled. However the scheduler will still accept schedule requests. """ self._runner.start()