Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: name 'QGISAPP' is not defined when using stop_app() #46883

Closed
2 tasks done
jakimowb opened this issue Jan 18, 2022 · 6 comments
Closed
2 tasks done

NameError: name 'QGISAPP' is not defined when using stop_app() #46883

jakimowb opened this issue Jan 18, 2022 · 6 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Build/Install Related to compiling or installing QGIS Feedback Waiting on the submitter for answers stale Uh oh! Seems this work is abandoned, and the PR is about to close.

Comments

@jakimowb
Copy link
Contributor

What is the bug or the crash?

The qgs.testing package provides the start_app and stop_app methods to run python tests.
However, stopping the QgsApplication raises an anyoing, but none-blocking NameError:

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "F:\OSGeo4W\apps\qgis-dev\python\qgis\testing\__init__.py", line 518, in exitQgis
    QGISAPP.exitQgis()
NameError: name 'QGISAPP' is not defined

Steps to reproduce the issue

Python code example:

from qgis.core import QgsApplication
from qgis.testing import start_app, stop_app

print(f'About to start: {QgsApplication.instance()}', flush=True)
start_app()
print(f'About to stop: {QgsApplication.instance()}', flush=True)
stop_app()
print(f'Stopped: {QgsApplication.instance()}', flush=True)

Versions

3.23.0-Master a9b522f (OSGeo4W)
3.23.0-Master 90f8c88 (Ubuntu)

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

  • I tried with a new QGIS profile

Additional context

No response

@jakimowb jakimowb added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jan 18, 2022
@gioman gioman added the Build/Install Related to compiling or installing QGIS label Jan 18, 2022
@elpaso
Copy link
Contributor

elpaso commented Jan 21, 2022

Cannot reproduce on Linux/master:

In [1]: from qgis.core import QgsApplication
   ...: from qgis.testing import start_app, stop_app
   ...: 
   ...: print(f'About to start: {QgsApplication.instance()}', flush=True)
   ...: start_app()
   ...: print(f'About to stop: {QgsApplication.instance()}', flush=True)
   ...: stop_app()
   ...: print(f'Stopped: {QgsApplication.instance()}', flush=True)
About to start: None
../src/core/symbology/qgssymbollayerutils.cpp:1270 : (loadSymbol) [331ms] no layers for symbol
../src/core/symbology/qgssymbollayerutils.cpp:1270 : (loadSymbol) [1ms] no layers for symbol
../src/core/providers/qgsproviderregistry.cpp:329 : (init) [53ms] Loaded 24 providers (DB2;OAPIF;WFS;arcgisfeatureserver;arcgismapserver;delimitedtext;ept;gdal;geonode;gpx;mdal;memory;mesh_memory;mssql;ogr;oracle;postgres;postgresraster;spatialite;vectortile;virtual;virtualraster;wcs;wms) 
Application state:
QGIS_PREFIX_PATH env var:               /home/user/dev/QGIS/build-local-qt5152-release_gdal3/output
Prefix:
Plugin Path:            /home/user/dev/QGIS/build-local-qt5152-release_gdal3/output/lib/qgis/plugins
Package Data Path:      /home/user/dev/QGIS/build-local-qt5152-release_gdal3/output/data
Active Theme Name:
Active Theme Path:      /home/user/dev/QGIS/build-local-qt5152-release_gdal3/output/data/resources/themes//icons/
Default Theme Path:     :/images/themes/default/
SVG Search Paths:       /home/user/dev/QGIS/build-local-qt5152-release_gdal3/output/data/svg/
                /tmp/QGIS-PythonTestConfigPath6jgv6h4l/profiles/default/svg/
User DB Path:   /home/user/dev/QGIS/build-local-qt5152-release_gdal3/output/data/resources/qgis.db
Auth DB Path:   /home/user/tmp/qgis-auth.db

About to stop: <qgis._core.QgsApplication object at 0x7fec8eb22dc0>
Stopped: None

@gioman gioman added the Feedback Waiting on the submitter for answers label Jan 21, 2022
@jakimowb
Copy link
Contributor Author

On my windows system it still occurs.
Interestingly the traceback printout got interrupted by the stdout Stopped: None

3.23.0-Master 50a68d40d7
About to start: None
Application state:
QGIS_PREFIX_PATH env var:		D:/OSGeo4W/apps/qgis-dev
Prefix:		D:/OSGeo4W/apps/qgis-dev
Plugin Path:		D:/OSGeo4W/apps/qgis-dev/plugins
Package Data Path:	D:/OSGeo4W/apps/qgis-dev/.
Active Theme Name:	
Active Theme Path:	D:/OSGeo4W/apps/qgis-dev/./resources/themes\\icons/
Default Theme Path:	:/images/themes/default/
SVG Search Paths:	D:/OSGeo4W/apps/qgis-dev/./svg/
		C:\Users\geo_beja\AppData\Local\Temp\QGIS-PythonTestConfigPath_koe8p7_\profiles\default/svg/
User DB Path:	D:/OSGeo4W/apps/qgis-dev/./resources/qgis.db
Auth DB Path:	C:\Users\geo_beja\AppData\Local\Temp\QGIS-PythonTestConfigPath_koe8p7_\profiles\default/qgis-auth.db

About to stop: <qgis._core.QgsApplication object at 0x0000025AAA833310>
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "D:\OSGeo4W\apps\qgis-dev\python\qgis\testing\__init__.py", line 518, in exitQgis
Stopped: None
    QGISAPP.exitQgis()
NameError: name 'QGISAPP' is not defined

Process finished with exit code 0

@github-actions
Copy link

github-actions bot commented Feb 5, 2022

The QGIS project highly values your report and would love to see it addressed. However, this issue has been left in feedback mode for the last 14 days and is being automatically marked as "stale".
If you would like to continue with this issue, please provide any missing information or answer any open questions. If you could resolve the issue yourself meanwhile, please leave a note for future readers with the same problem and close the issue.
In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this issue.
If there is no further activity on this issue, it will be closed in a week.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Feb 5, 2022
@jakimowb
Copy link
Contributor Author

jakimowb commented Feb 5, 2022

@elpaso have you tried running it from an IDE like QtCreator?

# relates to https://github.com/qgis/QGIS/issues/46883

from qgis.core import QgsApplication, Qgis
from qgis.testing import start_app, stop_app
import unittest

print(Qgis.version(), Qgis.devVersion(), flush=True)


class TestQGISAPP(unittest.TestCase):

    def test_StartAndClose(self):
        print(f'About to start: {QgsApplication.instance()}', flush=True)
        start_app()
        print(f'About to stop: {QgsApplication.instance()}', flush=True)
        stop_app()
        print(f'Stopped: {QgsApplication.instance()}', flush=True)


if __name__ == '__main__':
    unittest.main()

Running this from QtCreator on Ubuntu still outputs the error. However, it's none-blocking, the test finishes well and I cannot figure out how to capture the NameError to let the unittest fail.

image

@github-actions github-actions bot removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Feb 5, 2022
@github-actions
Copy link

The QGIS project highly values your report and would love to see it addressed. However, this issue has been left in feedback mode for the last 14 days and is being automatically marked as "stale".
If you would like to continue with this issue, please provide any missing information or answer any open questions. If you could resolve the issue yourself meanwhile, please leave a note for future readers with the same problem and close the issue.
In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this issue.
If there is no further activity on this issue, it will be closed in a week.

@github-actions github-actions bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Feb 20, 2022
@github-actions
Copy link

While we hate to see this happen, this issue has been automatically closed because it has not had any activity in the last 42 days despite being marked as feedback. If this issue should be reconsidered, please follow the guidelines in the previous comment and reopen this issue.
Or, if you have any further questions, there are also further support channels that can help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Build/Install Related to compiling or installing QGIS Feedback Waiting on the submitter for answers stale Uh oh! Seems this work is abandoned, and the PR is about to close.
Projects
None yet
Development

No branches or pull requests

3 participants