summaryrefslogtreecommitdiff
path: root/scheduler/status_server.py
diff options
context:
space:
mode:
authorshoward <showard@592f7852-d20e-0410-864c-8624ca9c26a4>2009-01-08 23:30:30 +0000
committershoward <showard@592f7852-d20e-0410-864c-8624ca9c26a4>2009-01-08 23:30:30 +0000
commit7f1168848168790203839e68130f08381fef91a8 (patch)
tree7e196056035f8736a14fe25114983cb5f8945ccf /scheduler/status_server.py
parent083bd75aaade0359517485e8673deb220fdafd59 (diff)
Make the status server smart enough to shut down cleanly when the scheduler exits. Some of this code is taken from tcpserver/tcpcommon.py. I'm not sure where we'd put the common code for these, or if it's too early for that.
Signed-off-by: Steve Howard <showard@google.com> git-svn-id: svn://test.kernel.org/autotest/trunk@2610 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'scheduler/status_server.py')
-rw-r--r--scheduler/status_server.py31
1 files changed, 22 insertions, 9 deletions
diff --git a/scheduler/status_server.py b/scheduler/status_server.py
index 2444f8df..b8832f01 100644
--- a/scheduler/status_server.py
+++ b/scheduler/status_server.py
@@ -1,4 +1,4 @@
-import os, BaseHTTPServer, cgi, threading
+import os, BaseHTTPServer, cgi, threading, urllib
import common
from autotest_lib.scheduler import scheduler_config
@@ -67,18 +67,31 @@ class StatusServerRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self.wfile.write(_FOOTER)
-class StatusServer(object):
+class StatusServer(BaseHTTPServer.HTTPServer):
def __init__(self):
- self._address = ('', _PORT)
- self._httpd = BaseHTTPServer.HTTPServer(self._address,
- StatusServerRequestHandler)
+ address = ('', _PORT)
+ # HTTPServer is an old-style class :(
+ BaseHTTPServer.HTTPServer.__init__(self, address,
+ StatusServerRequestHandler)
+ self._shutting_down = False
- def _run(self):
- print 'Status server running on', self._address
- self._httpd.serve_forever()
+ def shutdown(self):
+ if self._shutting_down:
+ return
+ print 'Shutting down server...'
+ self._shutting_down = True
+ # make one last request to awaken the server thread and make it exit
+ urllib.urlopen('http://localhost:%s' % _PORT)
+
+
+ def _serve_until_shutdown(self):
+ print 'Status server running on', self.server_address
+ while not self._shutting_down:
+ self.handle_request()
def start(self):
- self._thread = threading.Thread(target=self._run, name='status_server')
+ self._thread = threading.Thread(target=self._serve_until_shutdown,
+ name='status_server')
self._thread.start()