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

send_signal() only applies to parent process #78

Open
maxvirrozeito opened this issue Apr 24, 2018 · 2 comments
Open

send_signal() only applies to parent process #78

maxvirrozeito opened this issue Apr 24, 2018 · 2 comments

Comments

@maxvirrozeito
Copy link

I use spawn() within a spur shell. It creates a process on a remote machine as well as a child process (because of piped commands).

Then, when I want to kill the processes started (parent and child), I use:
process.send_signal(signal.SIGTERM)
but it only terminates the parent process.

In the implementation of send_signal() in SshProcess, I believe that a '-' sign in front of the PID would allow to terminate the full process group i.e. parent and child.
self._shell.run(["kill", "-{0}".format(signal), str(-self.pid)])

This change worked for me but I would like to hear the comments of one of the maintainers for spur.
Thanks

@mwilliamson
Copy link
Owner

Are you suggesting that the behaviour of the command be changed? Or are you suggesting a flag? Or something else?

In the meantime, since it's just running a kill command, you can implement your own version of send_signal() that sends the signal to the group.

@maxvirrozeito
Copy link
Author

For now, I am just calling directly a kill command to go around the default behaviour like you suggest.

But I think that spur would benefit from having the ability to kill a group of processes. Initially I was thinking about changing the behaviour of the send_signal() command but maybe an extra argument to that function would be better and provide the most flexibility:

def send_signal(self, signal, group=False):
   if group:
      self._shell.run(["kill", "-{0}".format(signal), str(-self.pid)])
   else:
      self._shell.run(["kill", "-{0}".format(signal), str(self.pid)])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants