(tests_pid)
| 19 | |
| 20 | |
| 21 | def main(tests_pid): |
| 22 | from debugpy.common import log, messaging |
| 23 | |
| 24 | # log.stderr_levels |= {"info"} |
| 25 | log.timestamp_format = "06.3f" |
| 26 | log_file = log.to_file(prefix="tests.watchdog") |
| 27 | |
| 28 | stream = messaging.JsonIOStream.from_stdio(f"tests-{tests_pid}") |
| 29 | log.info("Spawned WatchDog-{0} for tests-{0}", tests_pid) |
| 30 | tests_process = psutil.Process(tests_pid) |
| 31 | stream.write_json(["watchdog", log_file.filename]) |
| 32 | |
| 33 | spawned_processes = {} # pid -> ProcessInfo |
| 34 | try: |
| 35 | stop = False |
| 36 | while not stop: |
| 37 | try: |
| 38 | message = stream.read_json() |
| 39 | except Exception: |
| 40 | break |
| 41 | |
| 42 | command = message[0] |
| 43 | args = message[1:] |
| 44 | |
| 45 | if command == "stop": |
| 46 | assert not args |
| 47 | stop = True |
| 48 | |
| 49 | elif command == "register_spawn": |
| 50 | pid, name = args |
| 51 | pid = int(pid) |
| 52 | |
| 53 | log.info( |
| 54 | "WatchDog-{0} registering spawned process {1} (pid={2})", |
| 55 | tests_pid, |
| 56 | name, |
| 57 | pid, |
| 58 | ) |
| 59 | try: |
| 60 | _, old_name = spawned_processes[pid] |
| 61 | except KeyError: |
| 62 | pass |
| 63 | else: |
| 64 | log.warning( |
| 65 | "WatchDog-{0} already tracks a process with pid={1}: {2}", |
| 66 | tests_pid, |
| 67 | pid, |
| 68 | old_name, |
| 69 | ) |
| 70 | spawned_processes[pid] = ProcessInfo(psutil.Process(pid), name) |
| 71 | |
| 72 | elif command == "unregister_spawn": |
| 73 | pid, name = args |
| 74 | pid = int(pid) |
| 75 | |
| 76 | log.info( |
| 77 | "WatchDog-{0} unregistering spawned process {1} (pid={2})", |
| 78 | tests_pid, |
no test coverage detected
searching dependent graphs…