Chaitanya Sama Chaitanya Sama - 1 year ago 125
Python Question

Fabric does not close the ssh connection

I'm using fabric and trying to execute some commands on a remote machine.
I have written a python client which does this job.

def execute_command(timeout, command):
if timeout == -1:
return run(command, shell=False, pty=False, warn_only=True)
return run(command, shell=False, pty=False, warn_only=True, timeout=int(timeout))

It does schedule the job, but the problem is that whenever there is a job that takes more than 30 seconds or so, it never comes out of execute_command. And timeout does not work too.

When I do
ss -t | less
and check the socket activity, the ssh connection pertaining to that command is still active. And it remains active till I kill it. It never dies by itself.

Can you anybody help me out with this? I want it to come out and also for the timeout to work.

Answer Source

Figured it out.

When I disabled the psuedo terminal option in the arguments for run, I was able to achieve what I wanted.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download