X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=python3%2Fashd%2Fserve.py;h=87f60a0b017d2bd76a6b0dd252f83f89a5c1e0f6;hb=7aed82e3ad447ee4deb85959212f8d027cab03e5;hp=7811f66c155c0a8be2d313fd3f0fcea0bbf160eb;hpb=62220f392938f876514618b6742aed6e5555d6e1;p=ashd.git diff --git a/python3/ashd/serve.py b/python3/ashd/serve.py index 7811f66..87f60a0 100644 --- a/python3/ashd/serve.py +++ b/python3/ashd/serve.py @@ -207,7 +207,8 @@ class threadpool(handler): self.waitlimit = 5 self.wlstart = 0.0 self.qlk = threading.Lock() - self.qcond = threading.Condition(self.qlk) + self.qfcond = threading.Condition(self.qlk) + self.qecond = threading.Condition(self.qlk) self.max = max self.qsz = qsz self.timeout = timeout @@ -224,23 +225,23 @@ class threadpool(handler): return ret def handle(self, req): - start = False + spawn = False with self.qlk: if self.timeout is not None: now = start = time.time() while len(self.queue) >= self.qsz: - self.qcond.wait(start + self.timeout - now) + self.qecond.wait(start + self.timeout - now) now = time.time() if now - start > self.timeout: os.abort() else: - while len(self.current) >= self.qsz: - self.qcond.wait() + while len(self.queue) >= self.qsz: + self.qecond.wait() self.queue.append(req) - self.qcond.notify() + self.qfcond.notify() if len(self.waiting) < 1: - start = True - if start: + spawn = True + if spawn: with self.clk: if len(self.current) < self.max: th = reqthread(target=self.run) @@ -283,13 +284,14 @@ class threadpool(handler): try: if len(self.waiting) == self.waitlimit: self.wlstart = now - self.qcond.wait(start + timeout - now) + self.qfcond.wait(start + timeout - now) finally: self.waiting.remove(th) now = time.time() if now - start > timeout: return req = self.queue.popleft() + self.qecond.notify() try: self.handle1(req) finally: