Commit e4520e42 authored by Valentin Valls's avatar Valentin Valls
Browse files

Make wait-close gevent compliant

parent aca7b13b
......@@ -346,15 +346,22 @@ class FlintClient:
process = psutil.Process(pid)
self._proxy_create_flint_proxy(process)
def _wait_for_closed(self, pid, timeout=None):
@staticmethod
def _wait_for_closed(pid, timeout=None):
""""Wait for the PID to be closed"""
try:
p = psutil.Process(self._pid)
p = psutil.Process(pid)
except psutil.NoSuchProcess:
# process already closed
return
try:
with gevent.Timeout(timeout):
# gevent timeout have to be used here
# See https://github.com/gevent/gevent/issues/622
p.wait(timeout=None)
except gevent.Timeout:
pass
else:
psutil.wait_procs([p], timeout=timeout)
def close(self, timeout=None):
"""Close Flint and clean up this proxy."""
......
......@@ -91,11 +91,15 @@ def wait_terminate(process, timeout=10):
process.terminate()
try:
with gevent.Timeout(timeout):
# gevent timeout have to be used here
# See https://github.com/gevent/gevent/issues/622
process.wait()
except gevent.Timeout:
eprint(f"Process {name} doesn't finish: try to kill it...")
process.kill()
with gevent.Timeout(10):
# gevent timeout have to be used here
# See https://github.com/gevent/gevent/issues/622
process.wait()
......
......@@ -29,8 +29,11 @@ def kill_flint(pid):
pass
else:
try:
psutil.wait_procs([p], timeout=4.0)
except Exception:
with gevent.Timeout(4.0):
# gevent timeout have to be used here
# See https://github.com/gevent/gevent/issues/622
p.wait(timeout=None)
except gevent.Timeout:
assert False, "Flint was not closed as expected"
......
......@@ -4,6 +4,7 @@ import builtins
import pytest
import numpy
import psutil
import gevent
from bliss.shell import standard
from bliss.shell.standard import wa, wm, sta, stm, _launch_silx, umv
......@@ -343,7 +344,13 @@ def test_open_kill_flint(test_session_without_flint):
except psutil.NoSuchProcess:
pass
else:
psutil.wait_procs([process], timeout=1)
try:
with gevent.Timeout(1):
# gevent timeout have to be used here
# See https://github.com/gevent/gevent/issues/622
process.wait(timeout=None)
except gevent.Timeout:
pass
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