[ftputil] dealing with server timeout + GMANE
Stefan Schwarzer
sschwarzer at sschwarzer.net
Wed Dec 6 20:19:56 CET 2006
Hi Terrence,
On 2006-12-06 15:49, Terrence Brannon wrote:
> There was a trick in your code I had never seen before. The comma was
> necessary to create a sequence here:
>
> >>> t = threading.Thread(target=poll, args=(host,))
Yes, (1) is a "parenthesized" expression with the result 1
while (1,) is a tuple with the single element 1.
> Anyway, the program seems to head once I initiate the thread. I created a
> class for your code and then called it like below. I think throwing a simple
> chdir() in between each downloaded file should prevent the timeout, but I'd
> like to see if I can get the thread thing working anyway:
>
> import ftputil
> import time
> import threading
>
> class busyloop(object):
>
> def __init__(self,host):
> self.host = host
>
> def poll(self, host):
> while True:
> host.chdir(host.curdir)
> time.sleep(300)
Since you save the FTPHost object in busyloop's constructor,
you might access self.host in poll and spare the args argument
in Thread's constructor below.
> def loop(self):
> t = threading.Thread(target=self.poll, args=(self.host,))
> t.start()
> t.join()
Ooops, my mistake, sorry. Use t.setDaemon(True) _before_
the t.start() and _remove_ the t.join().
Does it work now?
> try:
> expected_files.remove(path(f).basename())
> except:
> pass
You should specifically catch the exceptions you may get.
Using except catches all kinds of exceptions, for example an
AttributeError if path(f) was a mistake and didn't contain
a basename attribute.
> shutil.copy(f, my.storage.input)
> shutil.move(f, my.storage.zip)
>
> if len(expected_files) != 0:
> print "Expected files", expected_files, "not on", my.cnf.dl.host
> sys.exit()
You can just write
if expected_files:
...
because an empty list is "false" for Python. I think, the main
advantage of if expected_files: isn't that it's shorter
but that is looks more "natural".
Stefan
More information about the ftputil
mailing list