@@ -332,11 +332,21 @@ def draw_if_interactive():
332332
333333
334334def _warn_if_gui_out_of_main_thread ():
335- # This compares native thread ids because even if python-level Thread
336- # objects match, the underlying OS thread (which is what really matters)
337- # may be different on Python implementations with green threads.
338- if (_get_required_interactive_framework (_get_backend_mod ())and
339- threading .get_native_id ()!= threading .main_thread ().native_id ):
335+ warn = False
336+ if _get_required_interactive_framework (_get_backend_mod ()):
337+ if hasattr (threading ,'get_native_id' ):
338+ # This compares native thread ids because even if Python-level
339+ # Thread objects match, the underlying OS thread (which is what
340+ # really matters) may be different on Python implementations with
341+ # green threads.
342+ if threading .get_native_id ()!= threading .main_thread ().native_id :
343+ warn = True
344+ else :
345+ # Fall back to Python-level Thread if native IDs are unavailable,
346+ # mainly for PyPy.
347+ if threading .current_thread ()is not threading .main_thread ():
348+ warn = True
349+ if warn :
340350_api .warn_external (
341351"Starting a Matplotlib GUI outside of the main thread will likely "
342352"fail." )