MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _test_threading

Function _test_threading

lib/matplotlib/tests/test_font_manager.py:311–341  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

309
310
311def _test_threading():
312 import threading
313 from matplotlib.ft2font import LoadFlags
314 import matplotlib.font_manager as fm
315
316 def loud_excepthook(args):
317 raise RuntimeError("error in thread!")
318
319 threading.excepthook = loud_excepthook
320
321 N = 10
322 b = threading.Barrier(N)
323
324 def bad_idea(n):
325 b.wait(timeout=5)
326 for j in range(100):
327 font = fm.get_font(fm.findfont("DejaVu Sans"))
328 font.set_text(str(n), 0.0, flags=LoadFlags.NO_HINTING)
329
330 threads = [
331 threading.Thread(target=bad_idea, name=f"bad_thread_{j}", args=(j,))
332 for j in range(N)
333 ]
334
335 for t in threads:
336 t.start()
337
338 for t in threads:
339 t.join(timeout=9)
340 if t.is_alive():
341 raise RuntimeError("thread failed to join")
342
343
344def test_fontcache_thread_safe():

Callers

nothing calls this directly

Calls 2

joinMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…