Added a bit of extra protectedness in PeriodicFileDownloader._downloadFile.

This commit is contained in:
Jeremy Fincher 2004-01-04 14:44:53 +00:00
parent 332a1826d5
commit 8fc6502ed3

View File

@ -199,7 +199,13 @@ class PeriodicFileDownloader(object):
self.getFile(filename)
def _downloadFile(self, filename, url, f):
try:
try:
infd = urllib2.urlopen(url)
except IOError, e:
self.log.warning('Error downloading %s', url)
self.log.exception('Exception:')
return
newFilename = os.path.join(conf.dataDir, utils.mktemp())
outfd = file(newFilename, 'wb')
start = time.time()
@ -209,7 +215,8 @@ class PeriodicFileDownloader(object):
s = infd.read(4096)
infd.close()
outfd.close()
self.log.info('Downloaded %s in %s seconds',filename,time.time()-start)
self.log.info('Downloaded %s in %s seconds',
filename, time.time()-start)
self.downloadedCounter[filename] += 1
self.lastDownloaded[filename] = time.time()
if f is None:
@ -223,7 +230,9 @@ class PeriodicFileDownloader(object):
start = time.time()
f(newFilename)
total = time.time() - start
self.log.info('Function ran on %s in %s seconds', filename, total)
self.log.info('Function ran on %s in %s seconds',
filename, total)
finally:
self.currentlyDownloading.remove(filename)
def getFile(self, filename):