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