I’ve started investigating using Prefect (2.8.6) Server for some job scheduling use-cases. The use case I have is pretty simple - start a task which spawns a subprocess via subprocess.Popen and wait for the result (needs to be a new process for a variety of reasons, such as clean python interpreter in potentially a different environment). Under normal circumstances that works great. However, when I attempt to cancel the process via the web UI the Popen process is left orphaned. Hopefully there’s already a workaround for what I’m trying to do but ideally the cancel signal can propagate to all child process, or my task can have some handler which recieves the signal and I can manually kills the processes myself. I also suspect that using Docker infra block might resolve it but didn’t want to try using that at this time unless there is a high level of confidence that would resolve this issue
1 Like
Resolved by using
@task(on_failure=[task_hook])
...
def task_hook(task, task_run, state):
print(f"In failure hook with {_PID}!")
# kill pid
1 Like