diff options
author | Tollef Fog Heen <tfheen@err.no> | 2018-03-10 11:26:45 +0100 |
---|---|---|
committer | Tollef Fog Heen <tfheen@err.no> | 2018-09-30 10:10:34 +0200 |
commit | fab34dc3431c41bb51b36951f558a44290d90467 (patch) | |
tree | 33d396ac5382ab069afc289790cd543943c420a0 /wee_slack.py | |
parent | 7cd77f1806647aeddb06d8da57d7fc7fd0e36845 (diff) | |
download | wee-slack-fab34dc3431c41bb51b36951f558a44290d90467.tar.gz |
Use an adaptive eventrouter timer
If there's more work, schedule ourselves more often, if there's less,
back off a bit to lessen the CPU load.
Fixes: #523
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/wee_slack.py b/wee_slack.py index 5cf8990..9847f8d 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -287,6 +287,8 @@ class EventRouter(object): self.shutting_down = False self.recording = False self.recording_path = "/tmp" + self.handle_next_hook = None + self.handle_next_hook_interval = -1 def record(self): """ @@ -490,6 +492,16 @@ class EventRouter(object): via callback to drain events from the queue. It also attaches useful metadata and context to events as they are processed. """ + wanted_interval = 100 + if len(self.slow_queue) > 0 or len(self.queue) > 0: + wanted_interval = 10 + if self.handle_next_hook is None or wanted_interval != self.handle_next_hook_interval: + if self.handle_next_hook: + w.unhook(self.handle_next_hook) + self.handle_next_hook = w.hook_timer(wanted_interval, 0, 0, "handle_next", "") + self.handle_next_hook_interval = wanted_interval + + if len(self.slow_queue) > 0 and ((self.slow_queue_timer + 1) < time.time()): # for q in self.slow_queue[0]: dbg("from slow queue", 0) @@ -4117,5 +4129,4 @@ if __name__ == "__main__": if config.record_events: EVENTROUTER.record() EVENTROUTER.handle_next() - w.hook_timer(10, 0, 0, "handle_next", "") # END attach to the weechat hooks we need |