diff options
author | Craig Tiller <ctiller@google.com> | 2017-04-24 17:50:32 +0000 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2017-04-24 17:50:32 +0000 |
commit | ea525ebd3949f89923f30da22471495e9e066326 (patch) | |
tree | e09c4b09f03bd9afd7cadec653b0943cdc01788f /tools | |
parent | 18548b8a0b2b703380e0c9525eb143027eaab9f3 (diff) |
Threaded port_server
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/run_tests/python_utils/port_server.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/tools/run_tests/python_utils/port_server.py b/tools/run_tests/python_utils/port_server.py index dbd32efc0e..67ae471582 100755 --- a/tools/run_tests/python_utils/port_server.py +++ b/tools/run_tests/python_utils/port_server.py @@ -33,18 +33,20 @@ from __future__ import print_function import argparse -from six.moves import BaseHTTPServer +from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler import hashlib import os import socket import sys import time +from SocketServer import ThreadingMixIn +import threading # increment this number whenever making a change to ensure that # the changes are picked up by running CI servers # note that all changes must be backwards compatible -_MY_VERSION = 9 +_MY_VERSION = 10 if len(sys.argv) == 2 and sys.argv[1] == 'dump_version': @@ -111,12 +113,12 @@ def allocate_port(req): keep_running = True -class Handler(BaseHTTPServer.BaseHTTPRequestHandler): +class Handler(BaseHTTPRequestHandler): def setup(self): # If the client is unreachable for 5 seconds, close the connection self.timeout = 5 - BaseHTTPServer.BaseHTTPRequestHandler.setup(self) + BaseHTTPRequestHandler.setup(self) def do_GET(self): global keep_running @@ -158,12 +160,12 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler): elif self.path == '/quitquitquit': self.send_response(200) self.end_headers() - keep_running = False + sys.exit(0) +class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): + """Handle requests in a separate thread""" -httpd = BaseHTTPServer.HTTPServer(('', args.port), Handler) -while keep_running: - httpd.handle_request() - sys.stderr.flush() -print('done') +httpd = ThreadedHTTPServer(('', args.port), Handler) +httpd.serve_forever() + |