From 76ff6c4dcf0bed028475ef646f4d637d8e91d1a7 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Mon, 6 Jan 2014 07:09:13 +0100 Subject: [PATCH] python: Fixed the real thread-starting problem. --- python/ashd/serve.py | 12 ++++++++---- python3/ashd/serve.py | 22 ++++++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/python/ashd/serve.py b/python/ashd/serve.py index a025cee..e9f92b0 100644 --- a/python/ashd/serve.py +++ b/python/ashd/serve.py @@ -142,15 +142,17 @@ class freethread(handler): while len(self.current) >= self.max: self.tcond.wait() th = reqthread(target=self.run, args=[req]) + th.registered = False th.start() - while th.is_alive() and th not in self.current: - self.tcond.wait(1) + while not th.registered: + self.tcond.wait() def run(self, req): try: th = threading.current_thread() with self.lk: self.current.add(th) + th.registered = True self.tcond.notify_all() try: env = req.mkenv() @@ -212,15 +214,17 @@ class resplex(handler): while len(self.current) >= self.max: self.tcond.wait() th = reqthread(target=self.handle1, args=[req]) + th.registered = False th.start() - while th.is_alive() and th not in self.current: - self.tcond.wait(1) + while not th.registered: + self.tcond.wait() def handle1(self, req): try: th = threading.current_thread() with self.lk: self.current.add(th) + th.registered = True self.tcond.notify_all() try: env = req.mkenv() diff --git a/python3/ashd/serve.py b/python3/ashd/serve.py index ce17b9d..db68a5f 100644 --- a/python3/ashd/serve.py +++ b/python3/ashd/serve.py @@ -108,6 +108,16 @@ class single(handler): finally: req.close() +def dbg(*a): + f = True + for o in a: + if not f: + sys.stderr.write(" ") + sys.stderr.write(str(a)) + f = False + sys.stderr.write("\n") + sys.stderr.flush() + class freethread(handler): cname = "free" @@ -142,15 +152,17 @@ class freethread(handler): while len(self.current) >= self.max: self.tcond.wait() th = reqthread(target=self.run, args=[req]) + th.registered = False th.start() - while th.is_alive() and th not in self.current: - self.tcond.wait(1) + while not th.registered: + self.tcond.wait() def run(self, req): try: th = threading.current_thread() with self.lk: self.current.add(th) + th.registered = True self.tcond.notify_all() try: env = req.mkenv() @@ -212,15 +224,17 @@ class resplex(handler): while len(self.current) >= self.max: self.tcond.wait() th = reqthread(target=self.handle1, args=[req]) + th.registered = False th.start() - while th.is_alive() and th not in self.current: - self.tcond.wait(1) + while not th.registered: + self.tcond.wait() def handle1(self, req): try: th = threading.current_thread() with self.lk: self.current.add(th) + th.registered = True self.tcond.notify_all() try: env = req.mkenv() -- 2.11.0