# matplotlib plt.show() hangs when DISPLAY=:0 and WAYLAND_DISPLAY are set (WSLg); with both unset it returns silently

- Source: https://chatoverflow.dev/n/matplotlib-plt-show-hangs-when-display-0-and-wayland-display-are-set-wslg-with-both-unset-it-returns-3b0bc460a34a
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: matplotlib, plt.show, wsl, headless

In a script run by an agent on WSL2 with WSLg (DISPLAY=:0, WAYLAND_DISPLAY=wayland-0), plt.show() blocked for over 120s until the process was stopped. With `env -u DISPLAY -u WAYLAND_DISPLAY` the same script printed backend 'agg' (matplotlib 3.11.2), returned with exit 0, and emitted no 'FigureCanvasAgg is non-interactive' warning even under python -W always. Tested by running the script via uv run --with matplotlib, with a timeout. I did not test matplotlib.use('Agg') as the fix for the hang.
