diff --git a/tools/run_tests/python_utils/port_server.py b/tools/run_tests/python_utils/port_server.py index 079ed70fbf3..10e9cf4c1a1 100755 --- a/tools/run_tests/python_utils/port_server.py +++ b/tools/run_tests/python_utils/port_server.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2.7 # Copyright 2015, Google Inc. # All rights reserved. # @@ -30,8 +30,6 @@ """Manage TCP ports for unit tests; started by run_tests.py""" -from __future__ import print_function - import argparse from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler import hashlib @@ -42,6 +40,7 @@ import time import random from SocketServer import ThreadingMixIn import threading +import platform # increment this number whenever making a change to ensure that @@ -51,7 +50,7 @@ _MY_VERSION = 19 if len(sys.argv) == 2 and sys.argv[1] == 'dump_version': - print(_MY_VERSION) + print _MY_VERSION sys.exit(0) @@ -67,13 +66,16 @@ if args.logfile is not None: sys.stderr = open(args.logfile, 'w') sys.stdout = sys.stderr -print('port server running on port %d' % args.port) +print 'port server running on port %d' % args.port pool = [] in_use = {} mu = threading.Lock() def can_connect(port): + # this test is only really useful on unices where SO_REUSE_PORT is available + # so on Windows, where this test is expensive, skip it + if platform.system() == 'Windows': return False s = socket.socket() try: s.connect(('localhost', port)) @@ -137,7 +139,7 @@ keep_running = True class Handler(BaseHTTPRequestHandler): - + def setup(self): # If the client is unreachable for 5 seconds, close the connection self.timeout = 5 @@ -195,6 +197,4 @@ class Handler(BaseHTTPRequestHandler): class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): """Handle requests in a separate thread""" - ThreadedHTTPServer(('', args.port), Handler).serve_forever() - diff --git a/tools/run_tests/python_utils/start_port_server.py b/tools/run_tests/python_utils/start_port_server.py index deb73544388..4acc964c7b1 100644 --- a/tools/run_tests/python_utils/start_port_server.py +++ b/tools/run_tests/python_utils/start_port_server.py @@ -27,9 +27,7 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -from __future__ import print_function - -from six.moves import urllib +import urllib import jobset import logging import os @@ -50,9 +48,9 @@ def start_port_server(): # otherwise, leave it up try: version = int( - urllib.request.urlopen( - 'http://localhost:%d/version_number' % _PORT_SERVER_PORT, - timeout=10).read()) + urllib.urlopen( + 'http://localhost:%d/version_number' % + _PORT_SERVER_PORT).read()) logging.info('detected port server running version %d', version) running = True except Exception as e: @@ -69,8 +67,8 @@ def start_port_server(): running = (version >= current_version) if not running: logging.info('port_server version mismatch: killing the old one') - urllib.request.urlopen('http://localhost:%d/quitquitquit' % - _PORT_SERVER_PORT).read() + urllib.urlopen('http://localhost:%d/quitquitquit' % + _PORT_SERVER_PORT).read() time.sleep(1) if not running: fd, logfile = tempfile.mkstemp() @@ -109,9 +107,8 @@ def start_port_server(): # try one final time: maybe another build managed to start one time.sleep(1) try: - urllib.request.urlopen( - 'http://localhost:%d/get' % _PORT_SERVER_PORT, - timeout=1).read() + urllib.urlopen( + 'http://localhost:%d/get' % _PORT_SERVER_PORT).read() logging.info( 'last ditch attempt to contact port server succeeded') break @@ -119,18 +116,18 @@ def start_port_server(): logging.exception( 'final attempt to contact port server failed') port_log = open(logfile, 'r').read() - print(port_log) + print port_log sys.exit(1) try: port_server_url = 'http://localhost:%d/get' % _PORT_SERVER_PORT - urllib.request.urlopen(port_server_url, timeout=1).read() + urllib.urlopen(port_server_url).read() logging.info('port server is up and ready') break except socket.timeout: logging.exception('while waiting for port_server') time.sleep(1) waits += 1 - except urllib.error.URLError: + except IOError: logging.exception('while waiting for port_server') time.sleep(1) waits += 1 diff --git a/tools/run_tests/start_port_server.py b/tools/run_tests/start_port_server.py index bfd72222b66..f7c9f43665e 100755 --- a/tools/run_tests/start_port_server.py +++ b/tools/run_tests/start_port_server.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2.7 # Copyright 2017, Google Inc. # All rights reserved. @@ -39,10 +39,8 @@ The path to this file is called out in test/core/util/port.c, and printed as an error message to users. """ -from __future__ import print_function - import python_utils.start_port_server as start_port_server start_port_server.start_port_server() -print("Port server started successfully") +print "Port server started successfully"