MCPcopy Create free account
hub / github.com/It4innovations/hyperqueue / check_task_processes_exited

Function check_task_processes_exited

tests/test_task_cleanup.py:161–197  ·  view source on GitHub ↗

Creates a task that spawns a child, and then calls `stop_fn`, which should kill either the task or the worker. The function then checks that both the task process and its child have been killed.

(hq_env: HqEnv, stop_fn: Callable[[subprocess.Popen], None], terminates_worker=True)

Source from the content-addressed store, hash-verified

159
160
161def check_task_processes_exited(hq_env: HqEnv, stop_fn: Callable[[subprocess.Popen], None], terminates_worker=True):
162 """
163 Creates a task that spawns a child, and then calls `stop_fn`, which should kill either the task
164 or the worker. The function then checks that both the task process and its child have been killed.
165 """
166 hq_env.start_server()
167 worker_process = hq_env.start_worker()
168
169 hq_env.command(
170 [
171 "submit",
172 "--",
173 *python(
174 """
175import os
176import sys
177import time
178print(os.getpid(), flush=True)
179pid = os.fork()
180if pid > 0:
181 print(pid, flush=True)
182time.sleep(3600)
183"""
184 ),
185 ]
186 )
187 wait_for_job_state(hq_env, 1, "RUNNING")
188 wait_until(lambda: len(read_file(default_task_output()).splitlines()) == 2)
189 pids = [int(pid) for pid in read_file(default_task_output()).splitlines()]
190
191 stop_fn(worker_process)
192
193 parent, child = pids
194 wait_for_pid_exit(parent)
195 wait_for_pid_exit(child)
196 if terminates_worker:
197 hq_env.check_process_exited(worker_process, None)

Calls 10

pythonFunction · 0.85
wait_for_job_stateFunction · 0.85
read_fileFunction · 0.85
default_task_outputFunction · 0.85
wait_for_pid_exitFunction · 0.85
commandMethod · 0.80
check_process_exitedMethod · 0.80
wait_untilFunction · 0.50
start_serverMethod · 0.45
start_workerMethod · 0.45

Tested by

no test coverage detected