Commit ed54215c authored by Jason R. Coombs's avatar Jason R. Coombs

Use serve_forever and shutdown, now available.

parent b2d5b933
......@@ -23,12 +23,8 @@ class IndexServer(HTTPServer):
HTTPServer.__init__(self, server_address, RequestHandlerClass)
self._run = True
def serve(self):
while self._run:
self.handle_request()
def start(self):
self.thread = threading.Thread(target=self.serve)
self.thread = threading.Thread(target=self.serve_forever)
self.thread.start()
def stop(self):
......@@ -37,19 +33,7 @@ class IndexServer(HTTPServer):
# Let the server finish the last request and wait for a new one.
time.sleep(0.1)
# self.shutdown is not supported on python < 2.6, so just
# set _run to false, and make a request, causing it to
# terminate.
self._run = False
url = 'http://127.0.0.1:%(server_port)s/' % vars(self)
try:
if sys.version_info >= (2, 6):
urllib2.urlopen(url, timeout=5)
else:
urllib2.urlopen(url)
except URLError:
# ignore any errors; all that's important is the request
pass
self.shutdown()
self.thread.join()
self.socket.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment