mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 07:54:36 +00:00
fix: properly terminate and wait on subprocesses on teardown
This commit is contained in:
@@ -388,12 +388,15 @@ def cmfactory(rpc, gencreds, maildomain, chatmail_config):
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def remote(sshdomain):
|
def remote(sshdomain):
|
||||||
return Remote(sshdomain)
|
r = Remote(sshdomain)
|
||||||
|
yield r
|
||||||
|
r.close()
|
||||||
|
|
||||||
|
|
||||||
class Remote:
|
class Remote:
|
||||||
def __init__(self, sshdomain):
|
def __init__(self, sshdomain):
|
||||||
self.sshdomain = sshdomain
|
self.sshdomain = sshdomain
|
||||||
|
self._procs = []
|
||||||
|
|
||||||
def iter_output(self, logcmd="", ready=None):
|
def iter_output(self, logcmd="", ready=None):
|
||||||
getjournal = "journalctl -f" if not logcmd else logcmd
|
getjournal = "journalctl -f" if not logcmd else logcmd
|
||||||
@@ -403,19 +406,32 @@ class Remote:
|
|||||||
case "localhost": command = []
|
case "localhost": command = []
|
||||||
case _: command = ["ssh", f"root@{self.sshdomain}"]
|
case _: command = ["ssh", f"root@{self.sshdomain}"]
|
||||||
[command.append(arg) for arg in getjournal.split()]
|
[command.append(arg) for arg in getjournal.split()]
|
||||||
self.popen = subprocess.Popen(
|
popen = subprocess.Popen(
|
||||||
command,
|
command,
|
||||||
|
stdin=subprocess.DEVNULL,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.DEVNULL,
|
||||||
)
|
)
|
||||||
while 1:
|
self._procs.append(popen)
|
||||||
line = self.popen.stdout.readline()
|
try:
|
||||||
res = line.decode().strip().lower()
|
while 1:
|
||||||
if not res:
|
line = popen.stdout.readline()
|
||||||
break
|
res = line.decode().strip().lower()
|
||||||
if ready is not None:
|
if not res:
|
||||||
ready()
|
break
|
||||||
ready = None
|
if ready is not None:
|
||||||
yield res
|
ready()
|
||||||
|
ready = None
|
||||||
|
yield res
|
||||||
|
finally:
|
||||||
|
popen.terminate()
|
||||||
|
popen.wait()
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
while self._procs:
|
||||||
|
proc = self._procs.pop()
|
||||||
|
proc.kill()
|
||||||
|
proc.wait()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|||||||
Reference in New Issue
Block a user