Skip to content

Commit

Permalink
Explicitly stop the test watchdog at exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
int19h committed Jul 18, 2019
1 parent c04d394 commit 40f1ded
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 8 additions & 0 deletions tests/watchdog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

__all__ = ["start", "register_spawn", "unregister_spawn"]

import atexit
import os
import sys
import psutil
Expand Down Expand Up @@ -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):
Expand Down
16 changes: 13 additions & 3 deletions tests/watchdog/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 40f1ded

Please sign in to comment.