Commit e71cbffe authored by Jim Fulton's avatar Jim Fulton

Don't use subprocess on windows. The close_fds option doesn't work on

windows and there's something aboyt the way we're setting up arguments
on windows that makes subproccess unhappy.

In the doctest support, save the pids along with adminaddrs and, when
we shutdown a server, wait for it to stop with os.waitpid. This is to
avoid a race where we end up trying and failing to delete the server's
log files before the server has closed them.
parent 7282dbd2
...@@ -129,6 +129,9 @@ def start_zeo_server(storage_conf=None, zeo_conf=None, port=None, keep=False, ...@@ -129,6 +129,9 @@ def start_zeo_server(storage_conf=None, zeo_conf=None, port=None, keep=False,
d = os.environ.copy() d = os.environ.copy()
d['PYTHONPATH'] = os.pathsep.join(sys.path) d['PYTHONPATH'] = os.pathsep.join(sys.path)
if sys.platform.startswith('win'):
pid = os.spawnve(os.P_NOWAIT, sys.executable, tuple(args), d)
else:
pid = subprocess.Popen(args, env=d, close_fds=True).pid pid = subprocess.Popen(args, env=d, close_fds=True).pid
adminaddr = ('localhost', port + 1) adminaddr = ('localhost', port + 1)
...@@ -270,7 +273,7 @@ def can_connect(port): ...@@ -270,7 +273,7 @@ def can_connect(port):
def setUp(test): def setUp(test):
ZODB.tests.util.setUp(test) ZODB.tests.util.setUp(test)
servers = [] servers = {}
def start_server(storage_conf=None, zeo_conf=None, port=None, keep=False, def start_server(storage_conf=None, zeo_conf=None, port=None, keep=False,
addr=None): addr=None):
...@@ -285,10 +288,10 @@ def setUp(test): ...@@ -285,10 +288,10 @@ def setUp(test):
port = addr[1] port = addr[1]
elif addr is not None: elif addr is not None:
raise TypeError("Can't specify port and addr") raise TypeError("Can't specify port and addr")
addr, adminaddr, _, config_path = start_zeo_server( addr, adminaddr, pid, config_path = start_zeo_server(
storage_conf, zeo_conf, port, keep) storage_conf, zeo_conf, port, keep)
os.remove(config_path) os.remove(config_path)
servers.append(adminaddr) servers[adminaddr] = pid
return addr, adminaddr return addr, adminaddr
test.globs['start_server'] = start_server test.globs['start_server'] = start_server
...@@ -299,15 +302,15 @@ def setUp(test): ...@@ -299,15 +302,15 @@ def setUp(test):
test.globs['get_port'] = get_port test.globs['get_port'] = get_port
def stop_server(adminaddr): def stop_server(adminaddr):
servers.remove(adminaddr) pid = servers.pop(adminaddr)
return shutdown_zeo_server(adminaddr) shutdown_zeo_server(adminaddr)
os.waitpid(pid, 0)
test.globs['stop_server'] = stop_server test.globs['stop_server'] = stop_server
def cleanup_servers(): def cleanup_servers():
while servers: for adminaddr in list(servers):
adminaddr = servers.pop() stop_server(adminaddr)
shutdown_zeo_server(adminaddr)
zope.testing.setupstack.register(test, cleanup_servers) zope.testing.setupstack.register(test, cleanup_servers)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment