super().__init__(name=name, **kw)
class wsgirequest(object):
- def __init__(self, handler):
+ def __init__(self, *, handler):
self.status = None
self.headers = []
self.respsent = False
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"
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:
+ while not th.registered:
self.tcond.wait()
def run(self, req):
th = threading.current_thread()
with self.lk:
self.current.add(th)
+ th.registered = True
self.tcond.notify_all()
try:
env = req.mkenv()
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:
+ while not th.registered:
self.tcond.wait()
def handle1(self, req):
th = threading.current_thread()
with self.lk:
self.current.add(th)
+ th.registered = True
self.tcond.notify_all()
try:
env = req.mkenv()
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:
- 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"):