diff --git a/tools/run_tests/port_server.py b/tools/run_tests/port_server.py index 41f862ad887..660928fbe79 100755 --- a/tools/run_tests/port_server.py +++ b/tools/run_tests/port_server.py @@ -81,9 +81,13 @@ def allocate_port(): return port +keep_running = True + + class Handler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): + global keep_running if self.path == '/get': # allocate a new port, it will stay bound for ten minutes and until # it's unused @@ -93,13 +97,21 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler): p = allocate_port() self.log_message('allocated port %d' % p) self.wfile.write('%d' % p) - elif self.path == '/version_and_pid': + elif self.path == '/version': # fetch a version string and the current process pid self.send_response(200) self.send_header('Content-Type', 'text/plain') self.end_headers() - self.wfile.write('%s+%d' % (_MY_VERSION, os.getpid())) + self.wfile.write(_MY_VERSION) + elif self.path == '/quit': + self.send_response(200) + self.end_headers() + keep_running = False + +httpd = BaseHTTPServer.HTTPServer(('', args.port), Handler) +while keep_running: + httpd.handle_request() -BaseHTTPServer.HTTPServer(('', args.port), Handler).serve_forever() +print 'done' diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 9cf52a191e3..28512a847c5 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -38,7 +38,6 @@ import json import multiprocessing import os import platform -import psutil import random import re import subprocess @@ -532,8 +531,7 @@ def _start_port_server(port_server_port): # if not running ==> start a new one # otherwise, leave it up try: - version, _, pid = urllib2.urlopen( - 'http://localhost:%d/version_and_pid' % port_server_port).read().partition('+') + version = urllib2.urlopen('http://localhost:%d/version' % port_server_port).read() running = True except Exception: running = False @@ -542,7 +540,8 @@ def _start_port_server(port_server_port): current_version = hashlib.sha1(f.read()).hexdigest() running = (version == current_version) if not running: - psutil.Process(int(pid)).terminate() + urllib2.urlopen('http://localhost:%d/quit' % port_server_port).read() + time.sleep(1) if not running: port_log = open('portlog.txt', 'w') port_server = subprocess.Popen(