-
Notifications
You must be signed in to change notification settings - Fork 225
Description
When I use the multi-threading features of the Qt GUI framework (PySide6) and call Transformer.transform from pyproj inside the thread, the Python process crashes after a low number of executed threads. It always works fine the first time pyproj is used inside a thread.
Here is a minimum example using a QRunnable inside QThreadPool:
from PySide6.QtCore import QRunnable, QThreadPool, QObject, Signal
from pyproj import Transformer
class WorkerSignals(QObject):
finished = Signal(float, float)
class TransformTask(QRunnable):
def __init__(self):
super().__init__()
self.signals = WorkerSignals()
def run(self):
lon, lat = 16.3738, 48.2082
transformer = Transformer.from_crs("EPSG:4326", "EPSG:32633", always_xy=True)
x, y = transformer.transform(lon, lat)
self.signals.finished.emit(x, y)
def print_result(x, y):
print(f"WGS84: (16.3738, 48.2082) -> UTM: ({x:.2f}, {y:.2f})")
for _ in range(100):
task = TransformTask()
task.signals.finished.connect(print_result)
QThreadPool.globalInstance().start(task)
Interestingly, the crash does no occur when using the standard threading module:
import threading
from pyproj import Transformer
def transform_coordinates():
lon, lat = 16.3738, 48.2082
transformer = Transformer.from_crs("EPSG:4326", "EPSG:32633", always_xy=True)
x, y = transformer.transform(lon, lat)
print(f"WGS84: ({lon}, {lat}) -> UTM: ({x:.2f}, {y:.2f})")
for _ in range(100):
t = threading.Thread(target=transform_coordinates)
t.start()
According to the Windows event report the crash originates from pyproj.libs\proj_9-ece80b3ce99919cf7dd31637c074a1bb.dll. The error code is 0xc0000005.
I am using PySide6 version 6.9.1. Here is the version info of my pyproj installation:
pyproj info:
pyproj: 3.7.1
PROJ (runtime): 9.5.1
PROJ (compiled): 9.5.1
PROJ DATA (recommended version): 1.20
PROJ Database: 1.4
EPSG Database: v11.022 [2024-11-05]
ESRI Database: ArcGIS Pro 3.4 [2024-11-04]
IGNF Database: 3.1.0 [2019-05-24]System:
python: 3.13.5 | packaged by Anaconda, Inc. | (main, Jun 12 2025, 16:37:03) [MSC v.1929 64 bit (AMD64)]
machine: Windows-11-10.0.26100-SP0Python deps:
certifi: 2025.7.14
Cython: None
setuptools: 78.1.1
pip: 25.1
This issue did not occur using Python 3.11.9 with pyproj 3.6.1 and PySide6 6.7.2.
Any ideas?
Thanks!