我编写了这个脚本,以便从特定的ftp上的数据中提取元数据,然后将其保存在特定的目录中,并等待一个随机时间并再次提取等等...... 所以有2点: :从特定的ftp提取 第二:保存并等待随机时间,这取决于所使用的ftp。Python异常后重新启动线程
有时候我有ftp超时问题。当它发生时,不再有提取,保存或等待线程。其他线程继续工作,直到它们也遇到超时问题。
我试图捕捉异常,以便“重新启动”涉及ftp超时问题的线程。但没有任何变化。
有人请帮我找到一种方法来“重新启动”线程?
许多感谢的
class ftp_id(Thread):
def __init__(self, ftpID):
Thread.__init__(self)
self.ftpID = ftpID
def run(self):
while True:
with verrou:
siteID = self.ftpID
directory = str(datetime.now())[:-16].replace('-', '')
filename = siteID + '_' + str(datetime.now())[:-7].replace(':', '').replace(' ', '_').replace('-', '') + '.txt'
dictstr = myExtract(siteID)
myWriteFile(directory, filename, dictstr)
pendingtime = myWaiting(siteID, dictstr)
time.sleep(pendingtime)
except :
self.stop = True
self.stop = False
self.start()
self.join()
thread_01 = ftp_id("ftp-01")
thread_02 = ftp_id("ftp-02")
thread_03 = ftp_id("ftp-03")
thread_04 = ftp_id("ftp-04")
thread_01.start()
thread_02.start()
thread_03.start()
thread_04.start()
thread_01.join()
thread_02.join()
thread_03.join()
thread_04.join()
所以它抛出一个异常?你为什么不在''True''循环中有'try-except'模块? –