I am experiencing a hard crash (the entire process terminates abruptly) whenever I execute GDAL translation or warping operations (gdal.Translate or gdal.Warp) synchronously in the main GUI thread of my PyQt5 application.
The GDAL operations work perfectly fine when running outside the PyQt environment. The crash occurs immediately upon calling the GDAL function (like gdal.Translate or gdal.Warp), which executes in the same thread that manages the UI.
Environment
- GUI Framework: PyQt5
- GIS Library: GDAL (Python bindings, version GDAL-3.10.1-cp313-cp313-win_amd64.whl)
- Python: 3.13.3
- Operating System: Windows 11
Minimal Code Context
The crash occurs when the main thread directly calls the GDAL logic, for instance, from a button click handler:
# main_window.py
# Synchronous call from the main GUI thread
class GeoGUI(QMainWindow):
...
def on_run_button_clicked(self):
params = {...}
geo = Geo(**params)
geo.run() # <-- Crash happens inside this function call
# main.py
if __name__ == "__main__":
app = QApplication(sys.argv)
window = GeoGUI()
QTimer.singleShot(0, window.showMaximized) # 0ms delay
sys.exit(app.exec_())
# Simplified Geo class snippet with its run() method
from osgeo import gdal, osr
from pyproj import Geod
class Geo():
...
def run(self):
# ... setup and GCPs ...
ds = gdal.Open(self.input_path, gdal.GA_ReadOnly)
try:
gdal.Translate(self.intermediate_vrt, ds, ...)
finally:
del ds
# ... gdal.Warp()
Steps Taken to Troubleshoot
I have confirmed the following best practices are in place:
- Initialization: Called
gdal.UseExceptions()in the Geo's init application entry point before any operations start. - Explicit Resource Management: Explicitly close all GDAL dataset
handles immediately after use using
del dsandtry...finallyblocks to ensure C-level resources are freed. - Error Handling: While
try...exceptis present, the hard crash prevents the Python exception handler from catching the error.
Question
Given that the GDAL operation is running synchronously on the main thread and causing a hard process crash, what is the most likely root cause?