Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e676ffb

Browse files
committed
Compare thread native ids when checking whether running on main thread.
1 parent 2716c82 commit e676ffb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/matplotlib/pyplot.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,11 @@ def draw_if_interactive():
329329

330330

331331
def _warn_if_gui_out_of_main_thread():
332-
if (_get_required_interactive_framework(_get_backend_mod())
333-
and threading.current_thread() is not threading.main_thread()):
332+
# This compares native thread ids because even if python-level Thread
333+
# objects match, the underlying OS thread (which is what really matters)
334+
# may be different on Python implementations with green threads.
335+
if (_get_required_interactive_framework(_get_backend_mod()) and
336+
threading.get_native_id() != threading.main_thread().native_id):
334337
_api.warn_external(
335338
"Starting a Matplotlib GUI outside of the main thread will likely "
336339
"fail.")

0 commit comments

Comments
 (0)