26
26
import re
27
27
import sys
28
28
import time
29
+ try :
30
+ import threading
31
+ except ImportError :
32
+ import dummy_threading as threading
29
33
30
34
from cycler import cycler
31
35
import matplotlib
@@ -177,6 +181,12 @@ def findobj(o=None, match=None, include_self=True):
177
181
return o .findobj (match , include_self = include_self )
178
182
179
183
184
+ def _get_required_interactive_framework ():
185
+ global _backend_mod
186
+ return getattr (
187
+ _backend_mod .FigureCanvas , "required_interactive_framework" , None )
188
+
189
+
180
190
def switch_backend (newbackend ):
181
191
"""
182
192
Close all open figures and set the Matplotlib backend.
@@ -224,8 +234,7 @@ class _backend_mod(matplotlib.backend_bases._Backend):
224
234
_log .debug ("Loaded backend %s version %s." ,
225
235
newbackend , _backend_mod .backend_version )
226
236
227
- required_framework = getattr (
228
- _backend_mod .FigureCanvas , "required_interactive_framework" , None )
237
+ required_framework = _get_required_interactive_framework ()
229
238
if required_framework is not None :
230
239
current_framework = cbook ._get_running_interactive_framework ()
231
240
if (current_framework and required_framework
@@ -248,6 +257,9 @@ class _backend_mod(matplotlib.backend_bases._Backend):
248
257
249
258
def new_figure_manager (* args , ** kwargs ):
250
259
"""Create a new figure manager instance."""
260
+ if (_get_required_interactive_framework ()
261
+ and threading .current_thread () is not threading .main_thread ()):
262
+ cbook ._warn_external ("Don't do this!" )
251
263
global _backend_mod
252
264
return _backend_mod .new_figure_manager (* args , ** kwargs )
253
265
@@ -276,6 +288,9 @@ def show(*args, **kwargs):
276
288
This is experimental, and may be set to ``True`` or ``False`` to
277
289
override the blocking behavior described above.
278
290
"""
291
+ if (_get_required_interactive_framework ()
292
+ and threading .current_thread () is not threading .main_thread ()):
293
+ cbook ._warn_external ("Don't do this!" )
279
294
global _backend_mod
280
295
return _backend_mod .show (* args , ** kwargs )
281
296
0 commit comments