Dolda2000 GitWeb
/
ashd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
lib: Fixed lingering stdchild bug.
[ashd.git]
/
python3
/
ashd
/
serve.py
diff --git
a/python3/ashd/serve.py
b/python3/ashd/serve.py
index
15e2903
..
db68a5f
100644
(file)
--- a/
python3/ashd/serve.py
+++ b/
python3/ashd/serve.py
@@
-23,7
+23,7
@@
class reqthread(threading.Thread):
super().__init__(name=name, **kw)
class wsgirequest(object):
super().__init__(name=name, **kw)
class wsgirequest(object):
- def __init__(self, handler):
+ def __init__(self,
*,
handler):
self.status = None
self.headers = []
self.respsent = False
self.status = None
self.headers = []
self.respsent = False
@@
-88,6
+88,8
@@
class handler(object):
return {}
class single(handler):
return {}
class single(handler):
+ cname = "single"
+
def handle(self, req):
try:
env = req.mkenv()
def handle(self, req):
try:
env = req.mkenv()
@@
-106,7
+108,19
@@
class single(handler):
finally:
req.close()
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):
class freethread(handler):
+ cname = "free"
+
def __init__(self, *, max=None, timeout=None, **kw):
super().__init__(**kw)
self.current = set()
def __init__(self, *, max=None, timeout=None, **kw):
super().__init__(**kw)
self.current = set()
@@
-138,8
+152,9
@@
class freethread(handler):
while len(self.current) >= self.max:
self.tcond.wait()
th = reqthread(target=self.run, args=[req])
while len(self.current) >= self.max:
self.tcond.wait()
th = reqthread(target=self.run, args=[req])
+ th.registered = False
th.start()
th.start()
- while
th.is_alive() and th not in self.current
:
+ while
not th.registered
:
self.tcond.wait()
def run(self, req):
self.tcond.wait()
def run(self, req):
@@
-147,6
+162,7
@@
class freethread(handler):
th = threading.current_thread()
with self.lk:
self.current.add(th)
th = threading.current_thread()
with self.lk:
self.current.add(th)
+ th.registered = True
self.tcond.notify_all()
try:
env = req.mkenv()
self.tcond.notify_all()
try:
env = req.mkenv()
@@
-179,6
+195,8
@@
class freethread(handler):
th.join()
class resplex(handler):
th.join()
class resplex(handler):
+ cname = "rplex"
+
def __init__(self, *, max=None, **kw):
super().__init__(**kw)
self.current = set()
def __init__(self, *, max=None, **kw):
super().__init__(**kw)
self.current = set()
@@
-206,8
+224,9
@@
class resplex(handler):
while len(self.current) >= self.max:
self.tcond.wait()
th = reqthread(target=self.handle1, args=[req])
while len(self.current) >= self.max:
self.tcond.wait()
th = reqthread(target=self.handle1, args=[req])
+ th.registered = False
th.start()
th.start()
- while
th.is_alive() and th not in self.current
:
+ while
not th.registered
:
self.tcond.wait()
def handle1(self, req):
self.tcond.wait()
def handle1(self, req):
@@
-215,6
+234,7
@@
class resplex(handler):
th = threading.current_thread()
with self.lk:
self.current.add(th)
th = threading.current_thread()
with self.lk:
self.current.add(th)
+ th.registered = True
self.tcond.notify_all()
try:
env = req.mkenv()
self.tcond.notify_all()
try:
env = req.mkenv()
@@
-266,15
+286,22
@@
class resplex(handler):
data = next(respiter)
except StopIteration:
rem = True
data = next(respiter)
except StopIteration:
rem = True
- req.flushreq()
+ try:
+ req.flushreq()
+ except:
+ log.error("exception occurred when handling response data", exc_info=True)
except:
rem = True
log.error("exception occurred when iterating response", exc_info=True)
if not rem:
if data:
except:
rem = True
log.error("exception occurred when iterating response", exc_info=True)
if not rem:
if data:
- req.flushreq()
- req.writedata(data)
- else:
+ try:
+ req.flushreq()
+ req.writedata(data)
+ except:
+ log.error("exception occurred when handling response data", exc_info=True)
+ rem = True
+ if rem:
current[req] = None
try:
if hasattr(respiter, "close"):
current[req] = None
try:
if hasattr(respiter, "close"):
@@
-326,9
+353,10
@@
class resplex(handler):
os.close(self.cnpipe[1])
self.rthread.join()
os.close(self.cnpipe[1])
self.rthread.join()
-names = {"single": single,
- "free": freethread,
- "rplex": resplex}
+names = {cls.cname: cls for cls in globals().values() if
+ isinstance(cls, type) and
+ issubclass(cls, handler) and
+ hasattr(cls, "cname")}
def parsehspec(spec):
if ":" not in spec:
def parsehspec(spec):
if ":" not in spec: