SFTPClient.stat freeze on concurrent invocation #718

idanarye opened this Issue Apr 3, 2016 · 1 comment


None yet

2 participants

idanarye commented Apr 3, 2016

When trying to invoke stat on the same SFTP connection from multiple threads, Paramiko can get stuck(deadlock?). For example:


HOSTNAME =  # replace with your own
USERNAME =  # replace with your own
KEY_FILENAME =  # replace with your own

from threading import Thread

from paramiko import SSHClient, AutoAddPolicy

ssh = SSHClient()
ssh.connect(hostname=HOSTNAME, username=USERNAME, key_filename=KEY_FILENAME)

sftp = ssh.open_sftp()

def print_root_stat(caption):
    print(caption, '\t', 'stat:', sftp.stat('/'))

print_root_stat('Main thread')

threads = [Thread(group=None, target=print_root_stat, args=('Thread %s' % i,), daemon=False) for i in range(10)]
for thread in threads:

When I run this I get:

Main thread      stat: dr-xr-xr-x   1 0        0            4096 03 Apr 13:51 ?
Thread 1         stat: dr-xr-xr-x   1 0        0            4096 03 Apr 13:51 ?
Thread 2         stat: dr-xr-xr-x   1 0        0            4096 03 Apr 13:51 ?

And that's it(it's always different threads that manage to run).

Does Paramiko's SFTP even supposed to support concurrency? Looking at the code it seems like it should, but I didn't see no such promise in the docs...


Suspect this falls under #578, which deals with threading locks & the SFTP client code. That should get merged and released soon. Please reopen this if nabbing a new release after that ticket gets resolved, doesn't fix your situation. Thanks!

@bitprophet bitprophet closed this Apr 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment