Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit70c7b91

Browse files
committed
Warn when trying to start a GUI event loop out of the main thread.
1 parent2a8d63b commit70c7b91

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

‎lib/matplotlib/pyplot.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
importre
2727
importsys
2828
importtime
29+
try:
30+
importthreading
31+
exceptImportError:
32+
importdummy_threadingasthreading
2933

3034
fromcyclerimportcycler
3135
importmatplotlib
@@ -177,6 +181,12 @@ def findobj(o=None, match=None, include_self=True):
177181
returno.findobj(match,include_self=include_self)
178182

179183

184+
def_get_required_interactive_framework():
185+
global_backend_mod
186+
returngetattr(
187+
_backend_mod.FigureCanvas,"required_interactive_framework",None)
188+
189+
180190
defswitch_backend(newbackend):
181191
"""
182192
Close all open figures and set the Matplotlib backend.
@@ -222,8 +232,7 @@ class _backend_mod(matplotlib.backend_bases._Backend):
222232
_log.debug("Loaded backend %s version %s.",
223233
newbackend,_backend_mod.backend_version)
224234

225-
required_framework=getattr(
226-
_backend_mod.FigureCanvas,"required_interactive_framework",None)
235+
required_framework=_get_required_interactive_framework()
227236
ifrequired_frameworkisnotNone:
228237
current_framework=cbook._get_running_interactive_framework()
229238
if (current_frameworkandrequired_framework
@@ -246,6 +255,9 @@ class _backend_mod(matplotlib.backend_bases._Backend):
246255

247256
defnew_figure_manager(*args,**kwargs):
248257
"""Create a new figure manager instance."""
258+
if (_get_required_interactive_framework()
259+
andthreading.current_thread()isnotthreading.main_thread()):
260+
cbook._warn_external("Don't do this!")
249261
global_backend_mod
250262
return_backend_mod.new_figure_manager(*args,**kwargs)
251263

@@ -274,6 +286,9 @@ def show(*args, **kwargs):
274286
This is experimental, and may be set to ``True`` or ``False`` to
275287
override the blocking behavior described above.
276288
"""
289+
if (_get_required_interactive_framework()
290+
andthreading.current_thread()isnotthreading.main_thread()):
291+
cbook._warn_external("Don't do this!")
277292
global_backend_mod
278293
return_backend_mod.show(*args,**kwargs)
279294

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp