From d2c39713bc821c59f3962fe4ae807b1d14c84ea8 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 12 Oct 2015 11:08:49 -0700 Subject: [PATCH] Attempt to daemonize port server --- tools/run_tests/port_server.py | 11 +++++++---- tools/run_tests/run_tests.py | 12 ++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tools/run_tests/port_server.py b/tools/run_tests/port_server.py index 4e473af4113..0593d7dc974 100755 --- a/tools/run_tests/port_server.py +++ b/tools/run_tests/port_server.py @@ -42,7 +42,7 @@ import time # 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 = 4 +_MY_VERSION = 5 if len(sys.argv) == 2 and sys.argv[1] == 'dump_version': @@ -124,9 +124,12 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler): self.send_header('Content-Type', 'text/plain') self.end_headers() p = int(self.path[6:]) - del in_use[p] - pool.append(p) - self.log_message('drop port %d' % p) + if p in in_use: + del in_use[p] + pool.append(p) + self.log_message('drop known port %d' % p) + else: + self.log_message('drop unknown port %d' % p) elif self.path == '/version_number': # fetch a version string and the current process pid self.send_response(200) diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 71377590221..2934b5f70f8 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -709,9 +709,17 @@ def _start_port_server(port_server_port): fd, logfile = tempfile.mkstemp() os.close(fd) print 'starting port_server, with log file %s' % logfile - port_server = subprocess.Popen( - [sys.executable, 'tools/run_tests/port_server.py', '-p', '%d' % port_server_port, '-l', logfile], + args = [sys.executable, 'tools/run_tests/port_server.py', '-p', '%d' % port_server_port, '-l', logfile] + if platform.system() == 'Windows': + port_server = subprocess.Popen( + args, + creationflags = 0x00000008, # detached process close_fds=True) + else: + port_server = subprocess.Popen( + args, + preexec_fn=os.setsid, + close_fds=True) time.sleep(1) # ensure port server is up waits = 0