Commit 80aa06e
authored
Windows: fix multi-thread safety (BoboTiG#159)
* Windows: fix multi-thread unsafe and update test
On Windows, the handle of entire window device context is saved to
`srcdc`. But the device context will be released once the thread who
creates it has died, so that `srcdc` is no loner valid. Replace `srcdc`
with `srcdc_dict` to maintain srcdc values created by multiple threads
which ensure the validity of srcdc when it's used.
A threading lock is add to prevent multiple threads from grabbing and
modifying shared class attributes `bmp`/`srcdc`/`memdc` (their windows
object in fact) at same time. Otherwise, unexpected screenshot or
unpredictable error will occur.
Add test_thread_safety in test_windows.py1 parent a8cb2d2 commit 80aa06e
File tree
5 files changed
+60
-6
lines changed- mss
- tests
5 files changed
+60
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
77 | 83 | | |
78 | 84 | | |
79 | 85 | | |
| |||
93 | 99 | | |
94 | 100 | | |
95 | 101 | | |
96 | | - | |
97 | | - | |
98 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
99 | 105 | | |
100 | 106 | | |
101 | 107 | | |
| |||
174 | 180 | | |
175 | 181 | | |
176 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
177 | 197 | | |
178 | 198 | | |
179 | 199 | | |
| |||
251 | 271 | | |
252 | 272 | | |
253 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
254 | 277 | | |
255 | 278 | | |
256 | 279 | | |
| |||
260 | 283 | | |
261 | 284 | | |
262 | 285 | | |
263 | | - | |
| 286 | + | |
264 | 287 | | |
265 | 288 | | |
266 | 289 | | |
| |||
287 | 310 | | |
288 | 311 | | |
289 | 312 | | |
| 313 | + | |
290 | 314 | | |
291 | 315 | | |
292 | 316 | | |
| |||
0 commit comments