From 407963f25c664cd1450ec5f6eeb80c449ff57e74 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Wed, 22 Jun 2016 04:30:06 +0200 Subject: [PATCH] python: Improved current-watcher implementation. --- python3/ashd/async.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/python3/ashd/async.py b/python3/ashd/async.py index e30f858..99da89a 100644 --- a/python3/ashd/async.py +++ b/python3/ashd/async.py @@ -3,12 +3,15 @@ import sys, os, errno, threading, select, traceback class epoller(object): exc_handler = None - def __init__(self): + def __init__(self, check=None): self.registered = {} self.lock = threading.RLock() self.ep = None self.th = None self.stopped = False + self.loopcheck = set() + if check is not None: + self.loopcheck.add(check) self._daemon = True @staticmethod @@ -56,6 +59,8 @@ class epoller(object): self.ep = ep while self.registered: + for ck in self.loopcheck: + ck(self) if self.stopped: self._closeall() break @@ -278,8 +283,7 @@ class callbuffer(channel): self.wp = -1 def currentwatcher(io, current): - def run(): - while current: - current.wait() - io.stop() - threading.Thread(target=run, name="Current watcher").start() + def check(io): + if not current: + io.stop() + io.loopcheck.add(check) -- 2.11.0