0
運行多個操作我試圖SFTP發佈到遠程機器蟒蛇多線程,我怎麼能在一次
與我的功能
def copyToServer(hostname, username, password, destPath, localPath):
transport = paramiko.Transport((hostname, 22))
transport.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(transport)
sftp.put(localPath, destPath)
sftp.close()
transport.close()
,我想文件並行
複製到多臺服務器如果已經嘗試了本
for i in range(xxx.xxx.xxx.111-xxx.xxx.xxx.210):
hostname = i
username = defaultLogin
password = defaultPassword
thread = threading.Thread(target=copyToServer, args=(hostname, username, password, destPath, localPath))
thread.start()
這給了我錯誤
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "testi.py", line 56, in copyToServer
log.write("%s FAILED - copying failed directory at remote machine doesn't exist\r\n" % hostname)
ValueError: I/O operation on closed file
你可以請提供一些有效的Python代碼範圍內的其他線程關閉'因爲我(xxx.xxx .xxx.111-xxx.xxx.xxx.210):' –