Commit bcec42b
FIX: move the font lock higher up the call and class tree
We have for a long time (~2012) had an RLock on `RenderAgg` that was used in
`FigureCanvasAgg.draw` to protect the shared cache of ft2font objects (the
underlying c++ is very stateful and not thread safe). This lock was also
implicitly protecting the mathtext cache when using the Agg backend.
However, given the recent improvements to the layout code there are now ways to
call call `Figure.draw(renderer)` without acquiring this lock which leads to
exceptions when using mathtext and a layout manager to save independent figures
on different threads.
This bug also exists for the other backendends which use both the mathtext
parser and the ft2font cache in the case of rendering texts as paths (in the
vector backends).
The fix is to:
- pull the lock up to `Figure` so all renderer instances effectively share a
single lock
- acquire the lock in `Figure.draw` which is always the top entry point to
rendering a Figure.
Closes matplotlib#26289
Co-authored-by: Greg Lucas <[email protected]>1 parent 02d2e13 commit bcec42b
File tree
3 files changed
+36
-38
lines changed- lib/matplotlib
- backends
3 files changed
+36
-38
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
174 | 173 | | |
175 | 174 | | |
176 | 175 | | |
| |||
2147 | 2146 | | |
2148 | 2147 | | |
2149 | 2148 | | |
| 2149 | + | |
| 2150 | + | |
2150 | 2151 | | |
2151 | 2152 | | |
2152 | | - | |
2153 | 2153 | | |
2154 | 2154 | | |
2155 | 2155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| |||
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | 64 | | |
79 | 65 | | |
80 | 66 | | |
| |||
395 | 381 | | |
396 | 382 | | |
397 | 383 | | |
398 | | - | |
399 | | - | |
| 384 | + | |
400 | 385 | | |
401 | 386 | | |
402 | 387 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
2365 | 2366 | | |
2366 | 2367 | | |
2367 | 2368 | | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
2368 | 2381 | | |
2369 | 2382 | | |
2370 | 2383 | | |
| |||
3124 | 3137 | | |
3125 | 3138 | | |
3126 | 3139 | | |
3127 | | - | |
3128 | | - | |
3129 | 3140 | | |
3130 | 3141 | | |
3131 | 3142 | | |
3132 | | - | |
3133 | | - | |
3134 | | - | |
3135 | | - | |
3136 | | - | |
3137 | | - | |
3138 | | - | |
3139 | | - | |
3140 | | - | |
| 3143 | + | |
3141 | 3144 | | |
3142 | | - | |
3143 | | - | |
3144 | | - | |
| 3145 | + | |
| 3146 | + | |
| 3147 | + | |
| 3148 | + | |
| 3149 | + | |
| 3150 | + | |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
3145 | 3154 | | |
3146 | | - | |
3147 | | - | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + | |
3148 | 3158 | | |
3149 | | - | |
3150 | | - | |
3151 | | - | |
| 3159 | + | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
| 3163 | + | |
| 3164 | + | |
3152 | 3165 | | |
3153 | | - | |
| 3166 | + | |
3154 | 3167 | | |
3155 | 3168 | | |
3156 | 3169 | | |
| |||
0 commit comments