python - Handling parallel ftp download errors -


I am downloading multiple files from an FTP server using multiple sessions of Python. At some point a session (I suspect) reads the file that is being accessed through another process and throws the following error:

  Traceback (most recent call final) : File "F: \ utilities \ Python \ downloadFTP_NV.py", line 66,  

This code Block where I can not find the best way to handle errors and to go to the next file:

  Set up the # logic so that it's already downloaded or partially downloaded Do not download files again. Os.path.exists (fileCheck): # " File check "There is a file before the rename 'file' file '% s' already exists'% name pass elif os.path.exists (fileCheck2): #" fileCheck2 after rename is a file' print 'file " % S "already exists '% FILE pass other: Try: f.cwd (DIRN + folder) start = time.coc () f.retrbinary (' RETR% s '% FILE, open (file,' wb ') .write) end = time.clock () arcpy.Rename_management (os.path.join (wor Ftplib.error_perm: print' error: file "% s" '% FILE os.unlink (FILE)  < Except for / pre> can not be read) (workspace, name) os.path.join (workspace, name) P> Extra Reducing Api processes to help I except  for  statement  time.sleep (5) is thought to add . Or perhaps just remove the  os.unlink (FILE)  line  What is the best way to handle such errors?  

I know this post is 3 years old, but for other users who Probably this is the problem, maybe I'll give possible solutions in your code, I do not think that if you close your file after the operation, then I think this is where the problem is with the as a best practice statement because it is a reference manager and a better error Handling.

Therefore, your part of the code where you should retrieve a file with OpenNote (File, 'WB') as Funnel: FTP TRABRARY ('RETR +', file written with Fennel)

  be it  

Your problem should be solved by that. And you do not need os.unlink (FILE)

if you need some background information about with statement, then this place is < / P>


Comments