I am writing a small program that runs through a ton of different shape files, tab files and geodatabases and gets their extent (about 10000- 100000 files).
I am opening these using the GDAL python library. I am using Python 2.7 and GDAL 2.2.3 on a windows 7 platform.
Unfortunately, some of these layers are completely corrupted, which causes GDAL to crash with a system error code.
ERROR:root:Could not read layer g:\31\23922\Tech\SWMM\Heatherton\Data\Heatherton_NS_draped.TAB
Process finished with exit code -1073741819 (0xC0000005)
My code looks like:
import ogr, logging, osr
path = r'g:\31\23922\Tech\SWMM\Heatherton\Data\Heatherton_NS_draped.TAB'
def check_path(path):
try:
logging.debug(path)
ds = ogr.Open(path)
if ds is None:
return None
for i in range(ds.GetLayerCount()):
print ds.GetLayerByIndex(i).GetExtent()
except:
import traceback
traceback.print_exc()
check_path(path)
print 'amIhere?'
I am fine with skipping this file. I just want to reach the
print 'amIhere?' part.
Or best case scenario: reach the except block.
But the fact that it uses an exit code, makes the entire thing crash. Is there a way to capture this?
I have tried catching SystemExit, BaseException....