Bug 2123692 - Importing Gtk in Python without a valid DISPLAY gives error message
Summary: Importing Gtk in Python without a valid DISPLAY gives error message
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: gtk3
Version: 8.5
Hardware: Unspecified
OS: Unspecified
Target Milestone: rc
: ---
Assignee: Matthias Clasen
QA Contact: Desktop QE
Depends On:
TreeView+ depends on / blocked
Reported: 2022-09-02 10:31 UTC by linma
Modified: 2022-11-16 11:39 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Last Closed: 2022-10-27 12:20:21 UTC
Type: Bug
Target Upstream Version:

Attachments (Terms of Use)

System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-133127 0 None None None 2022-09-02 10:36:18 UTC

Description linma 2022-09-02 10:31:15 UTC
Description of problem:

When the display is unset, importing Gtk in Python gives error message. The display is unset by default when ssh:ing to a machine.

Our use case is that 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.

How reproducible:

Always shows, given that the display is unset.

Steps to Reproduce:
Actual results:

Import Gtk in Python:
[cendio@lab-243 ~]$ DISPLAY= python3
Python 3.6.8 (default, Sep  9 2021, 07:49:02) 
[GCC 8.5.0 20210514 (Red Hat 8.5.0-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>> gi.require_version("Gtk", "3.0")
>>> from gi.repository import Gtk
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused

Expected results:
Importing Gtk should not give error messages. 

Additional info:
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. 

Additionally, this error message is not seen when importing Gtk in Python on RHEL 7.9 or RHEL 9.0.

Comment 1 Matthias Clasen 2022-10-27 12:19:08 UTC
As you say, this is not a GTK error message, so there is not really a GTK issue here that could be addressed in this bug.

If you want to handle the situation, you can wrap the import statement in a try: except: block, like this

import gi

    from gi.repository import Gtk
except ImportError:
    print("no display available")

The error message will still happen, unfortunately.

Comment 2 linma 2022-11-16 11:39:24 UTC
The cause of the error message seems to be file libgdk-3.so.0, so I would argue that it indeed is a GTK issue.

Further, this error message is only seen on RHEL 8, which uses GTK 3.22. When checking that version, the only hit I get is in gdkdisplay-broadway.c, which seems odd as we are not trying to use broadway.


Note You need to log in before you can comment on or make changes to this bug.