Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d4cf0f7

Browse filesBrowse files
committed
Fall back to Python-level Thread for GUI warning
This is mainly for the benefit of PyPy. Fixes #24094
1 parent c744161 commit d4cf0f7
Copy full SHA for d4cf0f7

File tree

Expand file treeCollapse file tree

1 file changed

+15
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-5
lines changed

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+15-5Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,21 @@ def draw_if_interactive():
332332

333333

334334
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:
340350
_api.warn_external(
341351
"Starting a Matplotlib GUI outside of the main thread will likely "
342352
"fail.")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.