[tarfile] Difficultis catching an exception
boblatest at googlemail.com
boblatest at googlemail.com
Wed Aug 20 05:07:33 EDT 2008
Hello,
I'm trying to catch an "EOFError" exception that occurs when reading
truncated tarfile. Here's my routine, and below that the callback
trace. Note that although I'm trying to catch all TarFile exceptions,
the tarfile.EOFError ecxeption, and the global EOFError exception, the
program still falls through and fails.
def query_archive(batch_base):
arc_name = os.path.join(archive_dir, 'B_'+batch_base+'.tar.bz2')
sys.stderr.write('Archive: %s ' % arc_name)
try:
archive = tarfile.open(arc_name, 'r:bz2')
members = archive.getmembers()
except tarfile.TarError, EOFError, tarfile.EOFError:
sys.stderr.write("corrupt.\n")
db.execute('UPDATE Archives SET Status=2 WHERE BatchBase=?',
(batch_base, ))
update_batchinfo(members, batch_base)
return 0
Archive: f:/wafermap_archive/B_48380.tar.bz2 Traceback (most recent
call last):
File "./wmap", line 11, in <module>
task.run(command, args)
File "/cygdrive/h/wafermaps/wmap_import.py", line 142, in run
query_archive(batch_base)
File "/cygdrive/h/wafermaps/wmap_import.py", line 95, in
query_archive
members = archive.getmembers()
File "/usr/lib/python2.5/tarfile.py", line 1282, in getmembers
self._load() # all members, we first have to
File "/usr/lib/python2.5/tarfile.py", line 2003, in _load
tarinfo = self.next()
File "/usr/lib/python2.5/tarfile.py", line 1809, in next
self.fileobj.seek(self.offset)
EOFError: compressed file ended before the logical end-of-stream was
detected
More information about the Python-list
mailing list