1

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

  1. GUI Framework: PyQt5
  2. GIS Library: GDAL (Python bindings, version GDAL-3.10.1-cp313-cp313-win_amd64.whl)
  3. Python: 3.13.3
  4. 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 ds and try...finally blocks to ensure C-level resources are freed.
  • Error Handling: While try...except is 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?

1 Answer 1

0

I fixed the issue by importing GDAL first, which helps to establishe its C-level environment in a clean state. Qt, being a more comprehensive and robust application framework, is designed to successfully initialize around the essential state of core libraries like GDAL, preventing the fatal conflict.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.