-
Notifications
You must be signed in to change notification settings - Fork 152
Event when one remote command has finished #296
-
Hi pkittenis,
Thx for your work!
I have to run commands that do not terminate on multiple remotes.
I am interested in getting notified when any remote command finished (e.g. the command encountered an unexpected error and exited, the process crashed, etc.).
While browsing the documentation,
I could not find any other way than polling around this snipped:
try: client.join(output, timeout=5) except Timeout as ex: # Some commands timed out finished_output = ex.args[2] unfinished_output = ex.args[3] else: # No timeout, all commands finished within five seconds finished_output = output unfinished_output = None
and checking if finished_output
is populated.
Do you know any other way?
Regards
Beta Was this translation helpful? Give feedback.
All reactions
Hi,
Thanks for the interest. Short answer is no. Callback support is tracked by #275.
It could be done client side by spawning callback greenlets on top of SSHClient.wait_finished
. Eg, something like:
from gevent import spawn
def my_cb(host_out):
try:
host_out.client.wait_finished()
except Exception as ex:
exc = ex
else:
exc = None
print(f"Command on host {host_out.host} exited with error code {host_out.exit_code}, exception {exc}")
output = client.run_command(<..>)
callbacks = [spawn(my_cb, host_out) for host_out in output]
Can similarly do something other than print in the callback.
wait_finished
will block the current greenlet. Anything afte...
Replies: 1 comment
-
Hi,
Thanks for the interest. Short answer is no. Callback support is tracked by #275.
It could be done client side by spawning callback greenlets on top of SSHClient.wait_finished
. Eg, something like:
from gevent import spawn
def my_cb(host_out):
try:
host_out.client.wait_finished()
except Exception as ex:
exc = ex
else:
exc = None
print(f"Command on host {host_out.host} exited with error code {host_out.exit_code}, exception {exc}")
output = client.run_command(<..>)
callbacks = [spawn(my_cb, host_out) for host_out in output]
Can similarly do something other than print in the callback.
wait_finished
will block the current greenlet. Anything after it will only be run if the command terminates for whatever reason. wait_finished
needs to be run in a new greenlet to run in background.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1