Skip to content

[Bug]: get_backend() will get stuck if DISPLAY cannot be connected #26760

Open
@maltoze

Description

@maltoze

Bug summary

matplotlib.get_backend() will get stuck if DISPLAY cannot be connected. Maybe should consider adding a timeout here.

if (getenv("DISPLAY")
&& (libX11 = dlopen("libX11.so.6", RTLD_LAZY))) {
struct Display* display = NULL;
struct Display* (* XOpenDisplay)(char const*) =
dlsym(libX11, "XOpenDisplay");
int (* XCloseDisplay)(struct Display*) =
dlsym(libX11, "XCloseDisplay");
if (XOpenDisplay && XCloseDisplay
&& (display = XOpenDisplay(NULL))) {
XCloseDisplay(display);
}
if (dlclose(libX11)) {
PyErr_SetString(PyExc_RuntimeError, dlerror());
return NULL;
}
if (display) {
Py_RETURN_TRUE;
}
}

Code for reproduction

import matplotlib
matplotlib.get_backend()

Actual outcome

get stuck

Expected outcome

return headless if DISPLAY cannot be connected

Additional information

No response

Operating system

No response

Matplotlib Version

3.7.3

Matplotlib Backend

No response

Python version

3.11.3

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions