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.")