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()
print(caption, '\t', 'stat:', sftp.stat('/'))
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!