qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.39k stars 2.98k forks source link

Python error - faulthandler - in QGIS LTR #52987

Open dlejay opened 1 year ago

dlejay commented 1 year ago

What is the bug or the crash?

An error occurred during execution of following code:
faulthandler.enable(file=fault_handler_file)

Traceback (most recent call last):
  File "", line 1, in 
PermissionError: [Errno 1] Operation not permitted

Python version:
3.10.11 (main, Apr  8 2023, 02:11:11) [Clang 14.0.0 (clang-1400.0.29.202)]

QGIS version:
3.28.6-Firenze 'Firenze', exported

Steps to reproduce the issue

Start QGIS and get greeted with a “Python error” popup.

Notice : this does only happens ~ half of the time when starting QGIS.

Versions

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">

QGIS version | 3.28.6-Firenze | QGIS code branch | Release 3.28 -- | -- | -- | -- Qt version | 5.15.8 Python version | 3.10.11 GDAL/OGR version | 3.6.4 PROJ version | 9.2.0 EPSG Registry database version | v10.082 (2023-02-06) GEOS version | 3.11.2-CAPI-1.17.2 SQLite version | 3.41.2 PDAL version | 2.5.2 PostgreSQL client version | unknown SpatiaLite version | 5.0.1 QWT version | 6.1.6 QScintilla2 version | 2.13.3 OS version | macOS 13.3   |   |   |   Active Python plugins processing | 2.12.99 sagaprovider | 2.12.99 grassprovider | 2.12.99 db_manager | 0.1.20 MetaSearch | 0.3.6 QGIS version 3.28.6-Firenze QGIS code branch [Release 3.28](https://github.com/qgis/QGIS/tree/release-3_28) Qt version 5.15.8 Python version 3.10.11 GDAL/OGR version 3.6.4 PROJ version 9.2.0 EPSG Registry database version v10.082 (2023-02-06) GEOS version 3.11.2-CAPI-1.17.2 SQLite version 3.41.2 PDAL version 2.5.2 PostgreSQL client version unknown SpatiaLite version 5.0.1 QWT version 6.1.6 QScintilla2 version 2.13.3 OS version macOS 13.3 Active Python plugins processing 2.12.99 sagaprovider 2.12.99 grassprovider 2.12.99 db_manager 0.1.20 MetaSearch 0.3.6 ### Supported QGIS version - [X] I'm running a supported QGIS version according to the roadmap. ### New profile - [ ] I tried with a new QGIS profile ### Additional context _No response_
BryanWall commented 1 year ago

The issue is still happening for me on v3.28.6, just compiled from source today

Firefishy commented 1 year ago

I get this too. macOS. Installed via conda. I wonder if it is some macOS permissions affecting the startup.

v3.32.0

Firefishy commented 1 year ago

I can confirm I tried with a new QGIS profile and I still get the same error.

simenojensen commented 1 year ago

I also have this issue on QGIS 3.32.2-Lima

Paree24 commented 1 year ago

Getting the same error

justinbb commented 8 months ago

The problem is that the Python error handler is being initialized too early (in the constructor of the QGIS app object). Yes, this has always worked in the past, but it is not okay on Apple Silicon Macs, for unknown reasons – though trying to do everything in the app object constructor is not always possible. Not dependent on packaging environment (MacPorts, Conda, etc.), error happens in all Apple Silicon builds.

After dismissing the frightening error dialog, one can use QGIS with no apparent problems. However, the Python error handler is NOT present and a Python error will crash the whole thing. Note that if the error handler is removed and reinstalled (using the Python console), it will work correctly. Thus I conclude that the only problem is the timing of the error handler installation; if it is done later, it is fine.

andrensc commented 1 month ago

Have the same issue on an M1 with QGIS 3@justinbb Can I induce a Python error to know if my installation is compromised? Besides how do you remove and reinstall the error handler?

bhjolly commented 3 weeks ago

@justinbb any chance of a quick tip for how to remove/install the faulthandler using the python console? Google/documentation are not helpful and I'm getting hard crashes using the 'Reshape features' tool on a vector layer that are just killing me (I assume fixing the faulthandler might help with that)

justinbb commented 3 weeks ago

@andrensc @bhjolly I think this is sufficient: – show the Python console (menu Plugins > Python Console) – at the prompt, type the following lines (taken from QGIS/src/python/qgspythonutilsimpl.cpp)

import faulthandler
faulthandler.disable()
qgis.utils.__qgis_fault_handler_file=open(qgis.utils.__qgis_fault_handler_file_path, 'wt')
faulthandler.enable(file=qgis.utils.__qgis_fault_handler_file)

The purpose of the Python fault handler is to provide debugging information in case a fatal error occurs in Python code. It may or may not be relevant to the problem you're having.

bhjolly commented 3 weeks ago

Thanks @justinbb, I actually got the same error running that code in my console:

>>> import faulthandler
>>> faulthandler.disable()
True
>>> qgis.utils.__qgis_fault_handler_file=open(qgis.utils.__qgis_fault_handler_file_path, 'wt')
>>> faulthandler.enable(file=qgis.utils.__qgis_fault_handler_file)
Traceback (most recent call last):
  File "/Users/jollyb/micromamba/envs/qgis/lib/python3.12/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
PermissionError: [Errno 1] Operation not permitted

If I re-run that .enable line in the same session it doesn't throw it the second time. However on a restart I still get the popup with the faulthandler 'Operation not permitted' error. This is for QGIS 3.38 installed from conda-forge.

As a side note, even once that code was run my issue with the Reshape tool still caused a hard crash so not sure what's going on there (might try and log a new GH issue)

fhfonsecaa commented 1 week ago

I have the same issue:

An error occurred during execution of following code:
faulthandler.enable(file=qgis.utils.__qgis_fault_handler_file)

Traceback (most recent call last):
  File "", line 1, in 
PermissionError: [Errno 1] Operation not permitted

Python version:
3.12.6 | packaged by conda-forge | (main, Sep 11 2024, 04:57:14) [Clang 17.0.6 ]

QGIS version:
3.38.2-Grenoble 'Grenoble', exported

I installed from conda and I have the following system:

image