Issue #1012 resolved

process/plugins.py:PerpetualTimer wakes up CPU 20 times per second.

guest
created an issue

threading._Timer slightly-busy waits in order to remain responsive to interrupts.

A daemon thread is adequate for most uses however, so the overhead required to be responsive to interrupts is unnecessary.

The following is a proposal for an alternate implementation. {{{ class PerpetualTimer(threading.Thread): """Periodically call a callback in a daemon thread.""" def init(self, frequency, callback): self.frequency = frequency self.callback = callback self.cancelled = False threading.Thread.init(self) self.setDaemon(True)

def run(self): while not self.cancelled: self.callback() time.sleep(self.frequency)

def cancel(self): self.cancelled = True

def join(self, args, *kargs): pass }}}

Once all callers are verified to not join on the thread when they're just planning on exiting, the no-op join call should be removed to restore the normal join behaviour.

Comments (2)

  1. Log in to comment