scheduler.py

changeset 75
2a44b9649212
parent 69
8705e296c7a0
child 76
4b08fca3ce34
--- a/scheduler.py	Fri Jan 26 19:04:04 2018 +0000
+++ b/scheduler.py	Sat Jan 27 12:19:39 2018 +0000
@@ -73,11 +73,14 @@
 
     def _insert(self, ev):
         if not self._list:
+            #logger.debug("Insert first")
             self._list=ev
         elif ev<self._list:
+            #logger.debug("Insert beginning")
             self._list.insert_immediately_before(ev)
             self._list=ev
         else:
+            #logger.debug("Insert after")
             self._list.insert_after(ev)
 
         self._cond.notify()
@@ -98,6 +101,7 @@
         super().__init__(target = self._scheduler_thread, name = 'Scheduler')
 
     def _scheduler_thread(self):
+        logger.debug("Scheduler thread started")
         with self._cond:
             while not self._terminate:
                 now = time.monotonic()
@@ -109,9 +113,12 @@
                     timeout=min(self.precision, self._list.when-now)
 
                 if not timeout or timeout>0:
+                    logger.debug("Scheduler waiting %d seconds" % (timeout or (-1)))
                     self._cond.wait(timeout)
                     now = time.monotonic()
 
+                logger.debug("Scheduler timed out")
+
                 while self._list and self._list.when <= now:
                     ev=self._list
                     logger.debug("Scheduler activating %s" % (ev.name or "(unknown)"))
@@ -136,5 +143,6 @@
 
     # cond has to be acquired on entry!
     def wait_until(self, when, cond, name=None):
+        logger.debug("Scheduling '%s' at %d" % (name, when))
         self._wait(ScheduledEvent(when, cond, name))
 

mercurial