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

Skip to content

Fall back to Python-level Thread for GUI warning #24178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,21 @@ def draw_if_interactive():


def _warn_if_gui_out_of_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):
warn = False
if _get_required_interactive_framework(_get_backend_mod()):
if hasattr(threading, 'get_native_id'):
# 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 threading.get_native_id() != threading.main_thread().native_id:
warn = True
else:
# Fall back to Python-level Thread if native IDs are unavailable,
# mainly for PyPy.
if threading.current_thread() is not threading.main_thread():
warn = True
if warn:
_api.warn_external(
"Starting a Matplotlib GUI outside of the main thread will likely "
"fail.")
Expand Down