Importing Gtk in Python without a valid DISPLAY gives error message
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gtk+3.0 (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Seen on Ubuntu 20.04
libgtk-3-0 version 3.24.20
Use case
========
We want to check if Gtk is available without actually using it. Once we confirm that it is available we can start using it, or take another route if it is unavailable.
Steps to reproduce
==================
The display must be unset, which is the default behaviour when ssh:ing to a machine. Then import Gtk in Python to get the error message.
cendio@
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>> gi.require_
>>> from gi.repository import Gtk
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused
Expected result
===============
Importing Gtk should not give error messages.
In Ubuntu 22.04, this issue is not present:
cendio@ubuntu-22:~$ DISPLAY= python3
Python 3.10.4 (main, Apr 2 2022, 09:04:19) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>> gi.require_
>>> from gi.repository import Gtk
Other comments
==============
Aside from the error message, everything seem to be working as expected. The errors are not Gtk errors, so it is unclear how they can be silenced.
affects: | snapd (Ubuntu) → gtk+3.0 (Ubuntu) |