File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -332,11 +332,21 @@ def draw_if_interactive():
332
332
333
333
334
334
def _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 :
340
350
_api .warn_external (
341
351
"Starting a Matplotlib GUI outside of the main thread will likely "
342
352
"fail." )
You can’t perform that action at this time.
0 commit comments