Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Ball <cjb@bob.laptop.org>2009-12-04 02:59:56 (GMT)
committer Chris Ball <cjb@bob.laptop.org>2009-12-04 02:59:56 (GMT)
commiteb2a9e2fe31195f079cbe22c1b4d03cc61c7c5b5 (patch)
tree2829572ca8849a46ed0e8689c746f38dab205da2
parentb35659fd3f2409583615d4118e99ad7cac8b4856 (diff)
server.py: fixes for python2.6 threading raising -EINTRs.
-rwxr-xr-xserver.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/server.py b/server.py
index 51e7164..a07c134 100755
--- a/server.py
+++ b/server.py
@@ -25,10 +25,12 @@ from __future__ import with_statement
import sys
import os
import subprocess
+import select
import codecs
from StringIO import StringIO
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
+import errno
import urllib
import re
import wp
@@ -45,6 +47,29 @@ except ImportError:
import mwlib.htmlwriter
from mwlib import parser, scanner, expander
+class MyHTTPServer(BaseHTTPServer.HTTPServer):
+ def serve_forever(self, poll_interval=0.5):
+ """Overridden version of BaseServer.serve_forever that does not fail
+ to work when EINTR is received.
+ """
+ self._BaseServer__serving = True
+ self._BaseServer__is_shut_down.clear()
+ while self._BaseServer__serving:
+ # XXX: Consider using another file descriptor or
+ # connecting to the socket to wake this up instead of
+ # polling. Polling reduces our responsiveness to a
+ # shutdown request and wastes cpu at all other times.
+ try:
+ r, w, e = select.select([self], [], [], poll_interval)
+ except select.error, e:
+ if e[0] == errno.EINTR:
+ print "got eintr"
+ continue
+ raise
+ if r:
+ self._handle_request_noblock()
+ self._BaseServer__is_shut_down.set()
+
class LinkStats:
allhits = 1
alltotal = 1
@@ -591,7 +616,7 @@ def load_db(dbname):
def run_server(path, port):
index = ArticleIndex('%s.index.txt' % path)
- httpd = BaseHTTPServer.HTTPServer(('', port),
+ httpd = MyHTTPServer(('', port),
lambda *args: WikiRequestHandler(index, *args))
if __name__ == '__main__':