python: Always properly close request handlers when exiting.
authorFredrik Tolf <fredrik@dolda2000.com>
Sun, 5 Jan 2014 08:57:51 +0000 (09:57 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Sun, 5 Jan 2014 08:57:51 +0000 (09:57 +0100)
python3/ashd-wsgi3
python3/scgi-wsgi3

index 79dda81..b250bce 100755 (executable)
@@ -192,5 +192,7 @@ class request(ashd.serve.wsgirequest):
 def handle(req):
     reqhandler.handle(request(bkreq=req, handler=reqhandler))
 
-ashd.util.serveloop(handle)
-reqhandler.close()
+try:
+    ashd.util.serveloop(handle)
+finally:
+    reqhandler.close()
index 1f5495d..946513e 100755 (executable)
@@ -132,9 +132,12 @@ class request(ashd.serve.wsgirequest):
     def close(self):
         self.sk.close()
 
-while True:
-    nsk, addr = sk.accept()
-    try:
-        reqhandler.handle(request(sk=nsk, handler=reqhandler))
-    finally:
-        nsk.close()
+try:
+    while True:
+        nsk, addr = sk.accept()
+        try:
+            reqhandler.handle(request(sk=nsk, handler=reqhandler))
+        finally:
+            nsk.close()
+finally:
+    reqhandler.close()