mwilliamson / spur.py

Run commands and manipulate files locally or over SSH using the same interface
BSD 2-Clause "Simplified" License
267 stars 37 forks source link

Do not leave python 2 blocked while SSH processes run (fixes #61) #74

Closed llvilanova closed 6 years ago

llvilanova commented 6 years ago

If we wait for an SSH process in Python 2, there is no way to cancel the script unless we send SIGKILL to it (e.g., SIGINT won't work).

The following example will never raise KeyboardInterrupt in Python 2 until the process finishes:

import spur s = spur.SshShell(hostname="localhost", missing_host_key=spur.ssh.MissingHostKey.accept) s.run(["bash", "-c", "sleep 100000"])

We instead add an active wait loop (only in Python 2) so that it can catch up with queued signals.

mwilliamson commented 6 years ago

This potentially causes an additional wait of up to 0.1 seconds, which I'd prefer to avoid by default.

llvilanova commented 6 years ago

It's only on older python versions, and a fairly small wait time. I can decrease it at the expense of processor time spent on busy-waiting.

Alternatively, is there any way to wait with a timeout on the child process? That would solve it without the extra wait.

llvilanova commented 6 years ago

Closing, see comment in #61.