Skip to content

Fix tqdm crash in TARGET (#116): route progress through QgsProcessingFeedback - #142

Merged
biglimp merged 1 commit into
UMEP-dev:mainfrom
jixuan-chen:fix/target-qgis-feedback
Aug 27, 2026
Merged

Fix tqdm crash in TARGET (#116): route progress through QgsProcessingFeedback#142
biglimp merged 1 commit into
UMEP-dev:mainfrom
jixuan-chen:fix/target-qgis-feedback

Conversation

@jixuan-chen

@jixuan-chen jixuan-chen commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #116.

tqdm writes its progress bar to sys.stdout, which QGIS sets to None when the Python console is not open, crashing with AttributeError: 'NoneType' object has no attribute 'write' (and the same for the logging calls in the same run).

target-py 0.2.0 adds an optional feedback parameter to Target(...) that routes progress through a QgsProcessingFeedback/QgsFeedback object instead of tqdm when one is provided. This wires it through in target_algorithm.py.

Requires target-py>=0.2.0. Companion PR bumping the version pin in umep-reqs: UMEP-dev/umep-reqs#15

Tested locally on QGIS 3.40.5 (macOS) by running the TARGET algorithm through the actual Processing Toolbox GUI with target-py 0.2.0 installed.

@biglimp

biglimp commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

This seems to fix the tdqm issue but I get another error when trying it on my windows 11 machine using our tutorial data. @jixuan-chen , can you see where the error might come from? Some version conflict in pandas (i have 3.0.2)

QGIS version: 3.44.9-Solothurn
QGIS code revision: 0bf732d52fb
Qt version: 5.15.13
Python version: 3.12.13
GDAL version: 3.12.3
GEOS version: 3.14.1-CAPI-1.20.5
PROJ version: Rel. 9.8.1, April 10th, 2026
PDAL version: 2.10.0 (git-version: bcdb32)
Algorithm started at: 2026-08-18T16:50:55
Algorithm 'Urban Heat Island: TARGET' starting…
Input parameters:
{ 'INPUT_FOLDER' : 'C:\\temp\\TARGETTutorial\\TARGETGBGCity\\GBGMay', 'INPUT_MET' : 'C:\\temp\\TARGETTutorial\\ERA5_GBG_2018_UMEP.txt', 'INPUT_POLYGONLAYER' : 'C:/temp/TARGETTutorial/gbgcity_grid_300m.shp', 'MOD_LDOWN' : False, 'OUTPUT_CSV' : False, 'OUTPUT_UMEP' : True, 'RUN_NAME' : 'gbg5', 'START_DATE' : QDate(2018, 4, 15), 'START_DATE_INTEREST' : QDate(2018, 5, 1), 'STOP_DATE_INTEREST' : QDate(2018, 6, 1) }

Model calculation started.
Traceback (most recent call last):
File "C:\Users/xlinfr/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\processing_umep\processor\target_algorithm.py", line 344, in processAlgorithm
tar.run_simulation(save_csv=False)
File "C:\OSGeo4W\apps\Python312\Lib\site-packages\target_py\scripts\toolkit.py", line 276, in run_simulation
eng_bals_rur1 = LUMPS(rad_rur1, self.parameters, self.cfM, met_d, ref_surf1, self.Dats, i)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\OSGeo4W\apps\Python312\Lib\site-packages\target_py\scripts\LUMPS.py", line 46, in LUMPS
Lambda = 2.501 - 0.002361 * met['Ta'][i] # MJ / kg - latent heat of vaporization
~~~~~~~~~^^^
File "C:\OSGeo4W\apps\Python312\Lib\site-packages\pandas\core\series.py", line 959, in __getitem__
return self._get_value(key)
^^^^^^^^^^^^^^^^^^^^
File "C:\OSGeo4W\apps\Python312\Lib\site-packages\pandas\core\series.py", line 1046, in _get_value
loc = self.index.get_loc(label)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\OSGeo4W\apps\Python312\Lib\site-packages\pandas\core\indexes\datetimes.py", line 993, in get_loc
raise KeyError(key)
KeyError: 0

Execution failed after 0.97 seconds

Loading resulting layers
Algorithm 'Urban Heat Island: TARGET' finished

@biglimp

biglimp commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

I fixed the issue above in this pr (jixuan-chen/target#17). I will merge this PR and then wait for you to make a new target-py version

@biglimp
biglimp merged commit be57033 into UMEP-dev:main Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strange error (only sometimes) in TARGET

2 participants