diff --git a/tests/watchdog/__init__.py b/tests/watchdog/__init__.py index b771393a3..5b977feb4 100644 --- a/tests/watchdog/__init__.py +++ b/tests/watchdog/__init__.py @@ -13,6 +13,7 @@ __all__ = ["start", "register_spawn", "unregister_spawn"] +import atexit import os import sys import psutil @@ -43,6 +44,13 @@ def start(): _stream = messaging.JsonIOStream(_process.stdout, _process.stdin, watchdog_name) assert _stream.read_json() == "ready" + atexit.register(stop) + + +def stop(): + if _stream is None: + return + _stream.write_json(["stop"]) def register_spawn(pid, name): diff --git a/tests/watchdog/worker.py b/tests/watchdog/worker.py index 15b3ded18..7c29914d6 100644 --- a/tests/watchdog/worker.py +++ b/tests/watchdog/worker.py @@ -45,10 +45,17 @@ def main(tests_pid): except Exception: break - command, pid, name = message - pid = int(pid) + command = message[0] + args = message[1:] + + if command == "stop": + assert not args + break + + elif command == "register_spawn": + pid, name = args + pid = int(pid) - if command == "register_spawn": log.debug( "watchdog-{0} registering spawned process {1} (pid={2})", tests_pid, @@ -59,6 +66,9 @@ def main(tests_pid): spawned_processes[pid] = psutil.Process(pid) elif command == "unregister_spawn": + pid, name = args + pid = int(pid) + log.debug( "watchdog-{0} unregistering spawned process {1} (pid={2})", tests_pid,