15 from __future__
import print_function
25 import six.moves.urllib.request
as request
27 sys.path.append(os.path.dirname(os.path.abspath(__file__)))
31 _PORT_SERVER_PORT = 32766
41 request.urlopen(
'http://localhost:%d/version_number' %
42 _PORT_SERVER_PORT).
read())
43 logging.info(
'detected port server running version %d', version)
45 except Exception
as e:
46 logging.exception(
'failed to detect port server')
49 current_version =
int(
50 subprocess.check_output([
52 os.path.abspath(
'tools/run_tests/python_utils/port_server.py'),
55 logging.info(
'my port server is version %d', current_version)
56 running = (version >= current_version)
58 logging.info(
'port_server version mismatch: killing the old one')
59 request.urlopen(
'http://localhost:%d/quitquitquit' %
60 _PORT_SERVER_PORT).
read()
63 fd, logfile = tempfile.mkstemp()
65 logging.info(
'starting port_server, with log file %s', logfile)
68 os.path.abspath(
'tools/run_tests/python_utils/port_server.py'),
70 '%d' % _PORT_SERVER_PORT,
'-l', logfile
72 env = dict(os.environ)
73 env[
'BUILD_ID'] =
'pleaseDontKillMeJenkins'
74 if jobset.platform_string() ==
'windows':
77 tempdir = tempfile.mkdtemp()
78 if sys.version_info.major == 2:
79 creationflags = 0x00000008
82 port_server = subprocess.Popen(args,
85 creationflags=creationflags,
88 port_server = subprocess.Popen(args,
98 'killing port server due to excessive start up waits')
100 if port_server.poll()
is not None:
101 logging.error(
'port_server failed to start')
105 request.urlopen(
'http://localhost:%d/get' %
106 _PORT_SERVER_PORT).
read()
108 'last ditch attempt to contact port server succeeded')
112 'final attempt to contact port server failed')
113 port_log =
open(logfile,
'r').
read()
117 port_server_url =
'http://localhost:%d/get' % _PORT_SERVER_PORT
118 request.urlopen(port_server_url).
read()
119 logging.info(
'port server is up and ready')
121 except socket.timeout:
122 logging.exception(
'while waiting for port_server')
126 logging.exception(
'while waiting for port_server')
131 'error while contacting port server at "%s".'
132 'Will try killing it.', port_server_url)