Commit 3004d950 authored by Valentin Valls's avatar Valentin Valls
Browse files

Wait until flint is terminated

parent eb84f9f2
......@@ -92,19 +92,30 @@ class FlintClient:
def close_proxy(self):
if self._proxy is not None:
self._proxy.close()
if self._callbacks is not None:
stdout_callback, stderr_callback = self._callbacks
event.disconnect(self._proxy, "flint_stdout", stdout_callback)
event.disconnect(self._proxy, "flint_stderr", stderr_callback)
self._callbacks = None
self._proxy = None
self._pid = None
self._process = None
if self._greenlets is not None:
gevent.killall(self._greenlets)
gevent.killall(self._greenlets, timeout=2.0)
self._greenlets = None
self._callbacks = None
def close(self):
"""Close Flint and clean up this proxy."""
if self._proxy is None:
raise RuntimeError("No proxy connected")
self._proxy.close_application()
try:
p = psutil.Process(self._pid)
except psutil.NoSuchProcess:
# process already closed
pass
else:
psutil.wait_procs([p], timeout=4.0)
self.close_proxy()
def focus(self):
......
......@@ -561,13 +561,13 @@ def flint_context(with_flint=True):
else:
flint = plot.get_flint(creation_allowed=False)
if flint is not None:
flint.close_application()
flint.close()
flint = None # Break the reference to the proxy
plot.reset_flint()
yield
flint = plot.get_flint(creation_allowed=False)
if flint is not None:
flint.close_application()
flint.close()
flint = None # Break the reference to the proxy
plot.reset_flint()
......
......@@ -303,8 +303,6 @@ def test_open_close_flint(test_session_without_flint):
pid = f.pid
assert psutil.pid_exists(pid)
f.close()
process = psutil.Process(pid)
psutil.wait_procs([process], timeout=5)
assert not psutil.pid_exists(pid)
......@@ -314,7 +312,11 @@ def test_open_kill_flint(test_session_without_flint):
pid = f.pid
assert psutil.pid_exists(pid)
f.kill9()
try:
process = psutil.Process(pid)
except psutil.NoSuchProcess:
pass
else:
psutil.wait_procs([process], timeout=1)
assert not psutil.pid_exists(pid)
......
Supports Markdown
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