Mahesh Shitole February 2016

Could not terminate process when use paramiko for command execution

I have a python script which does remote command execution, and I want to use multiprocessing in it.

I managed to get the program itself working, but when trying to interrupt it using CTRL+C, I get the following exception, and the program doesn't terminate correctly:

Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 102, in worker
    task = get()
  File "/usr/lib/python2.7/multiprocessing/queues.py", line 376, in get
    return recv()
KeyboardInterrupt
Caught KeyboardInterrupt, terminating workers

What am I doing wrong?

Answers


emma sculateur February 2016

CTRL+C sends a SIGINT to the python process, which triggers a KeyboardInterrupt exception. Here, your parent process hits this exception, and since you are not catching it, it exits brutally, as well as its children.

If you want to handle CTRL+C, you need to catch this KeyboardInterrupt exception in your parent process. An example is given in this answer for instance. If you share your code we may find something more specific to your case.

Post Status

Asked in February 2016
Viewed 3,358 times
Voted 12
Answered 1 times

Search




Leave an answer