How does pants terminate a Process if it gets canc...
# plugins
b
How does pants terminate a Process if it gets cancelled? I have a bash script I am running with a Process that needs to do some cleanup on exit that doesn't seem to be doing so reliably. Wondering what I might be doing wrong
f
with SIGKILL
b
hmm my script is supposed to be trapping SIGKILL and running the cleanup
f
SIGKILL cannot be trapped. It immediately kills a process without any chance for the process to react.
(SIGTERM is the “nice” version which requests a process to terminate, and which can be trapped.)
If I may ask, since Pants executions happen in an execution sandbox, what is there to cleanup?
b
ah right. I am trapping sigterm
I've built a plugin with uses a buildah container to build an rpm. We need to be able to install other packages in the build environment which is why we add the container on top of pants
so pants only sends a sigkill and not a sigterm first? is there anyway to do the cleanup I want?
f
what does the cleanup do? Is it to remove a container?
b
yup the cleanup is to remove the container
f
you could do the cleanup in the Python rules (at the cost of an extra
Process
invocation)
buildah from
should return the container name, right? invoke that first and parse the stdout from the
Process
in Python to get the container name.
then invoke a second
Process
to complete the build step
if that step fails, then invoke
Process
to call buildah to delete the container
this would not work with remote execution though, but maybe that is okay?
b
yeah buildah does return the container name and I could get it back into pants. I would like to keep remote execution available as an option
I'd probably write the container_id to a file in the script and collect the file in pants. Then everything is still one process except the cleanup
f
yeah that would work better.
b
but if pants is cancelling it won't run any further processes right? so it wouldn't really solve my problem. I think I would need some kind of teardown or cleanup hook in pants itself
w
this was changed to SIGINT in 2.11.x: https://github.com/pantsbuild/pants/issues/13230
b
Amazing! thanks