From e676ffb4c984c1e15732a0a65e8100732d308180 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 18 Jul 2022 12:48:39 +0200 Subject: [PATCH] Compare thread native ids when checking whether running on main thread. --- lib/matplotlib/pyplot.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index b8c9b88f563f..4b161c1eee05 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -329,8 +329,11 @@ def draw_if_interactive(): def _warn_if_gui_out_of_main_thread(): - if (_get_required_interactive_framework(_get_backend_mod()) - and threading.current_thread() is not threading.main_thread()): + # This compares native thread ids because even if python-level Thread + # objects match, the underlying OS thread (which is what really matters) + # may be different on Python implementations with green threads. + if (_get_required_interactive_framework(_get_backend_mod()) and + threading.get_native_id() != threading.main_thread().native_id): _api.warn_external( "Starting a Matplotlib GUI outside of the main thread will likely " "fail.")