RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
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
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: gtk3
Version: 8.5
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Matthias Clasen
QA Contact: Desktop QE
URL:
Whiteboard:
Depends On:
Blocks:
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:
Environment:
Last Closed: 2022-10-27 12:20:21 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
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

try:
    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.

https://github.com/GNOME/gtk/blob/3.22.30/gdk/broadway/gdkdisplay-broadway.c#L112


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