Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kill tox process does not kill running commands #1772

Closed
dajose opened this issue Jan 6, 2021 · 3 comments · Fixed by #1860
Closed

kill tox process does not kill running commands #1772

dajose opened this issue Jan 6, 2021 · 3 comments · Fixed by #1860
Labels
bug:normal affects many people or has quite an impact

Comments

@dajose
Copy link

dajose commented Jan 6, 2021

Tox seems to not being sending the sigterm signal back to the subprocess it is driving.

This can be reproduced with this configuration, and killing the tox process.

tox.ini

[tox]
skipsdist = True

[testenv:papa]
commands =
    {envpython} {toxinidir}/papa.py

papa.py

from time import sleep
while True:
   sleep(1)
   print('papa')

from a terminal run

tox -e papa

and on another, search the process and kill it, for example:

diazdavi@darker:/tmp$ ps -aux | grep tox
diazdavi  779128  6.3  0.1 114196 22588 pts/0    S+   17:00   0:00 /usr/bin/python3 /usr/local/bin/tox -e papa
diazdavi  779140  0.5  0.0  26912  9500 pts/0    S+   17:00   0:00 /tmp/.tox/papa/bin/python papa.py
diazdavi  779178  0.0  0.0  17664  2700 pts/2    S+   17:00   0:00 grep --color=auto tox
diazdavi@darker:/tmp$ kill 779128

The first terminal will keep showing the prints :(

@dajose dajose added the bug:normal affects many people or has quite an impact label Jan 6, 2021
@gaborbernat
Copy link
Member

This is a side effects of how sub processes work. If you kill the tox process there's no way you can stop the subprocess. There's no way to mark a subprocess daemon to die with the parent.

@dajose
Copy link
Author

dajose commented Jan 7, 2021

@gaborbernat you are right, it is not the "natural" way of handling a parent process being killed. And if it were a SIGKILL signal there would be nothing to be done.

A kill by default sends a SIGTERM, and that you can capture on python using signal. For example (using the same papa.py script above)

import signal
signal.signal(signal.SIGTERM, signal.getsignal(signal.SIGINT))

from subprocess import run
run(['python3', 'papa.py'])

That code above is not my best work, but it takes a SIGTERM and make the parent process handle as it was a Ctrl+C. Which would in turn kill the children.

I wonder if we can reopen the issue, calling it a bug was my mistake. It is most likely an enhance request.

@dajose
Copy link
Author

dajose commented Jan 7, 2021

I forgot to mention, I found this while debugging an issue presented while running tox in a Jenkins instance... it seems that jenkins sends a SIGTERM on a job abort (jenkinsci/jenkins#3414)... and my tox commands are continuing to run after the abort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:normal affects many people or has quite an impact
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants