Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Commit3e25a93
committed
Take advantage of PyErr_CheckSignals now being callable without the GIL.
The source tree contains dozens of loops of this form: int res; do { Py_BEGIN_ALLOW_THREADS res = some_system_call(arguments...); Py_END_ALLOW_THREADS } while (res < 0 && errno == EINTR && !PyErr_CheckSignals());Now that it is possible to call PyErr_CheckSignals without holding theGIL, the locking operations can be moved out of the loop: Py_BEGIN_ALLOW_THREADS do { res = some_system_call(arguments...); } while (res < 0 && errno == EINTR && !PyErr_CheckSignals()); Py_END_ALLOW_THREADSThis demonstrates the motivation for making it possible to callPyErr_CheckSignals without holding the GIL. It shouldn’t make anymeasurable difference performance-wise for _these_ loops, which almostnever actually cycle; but for loops that do cycle many times it’s verymuch desirable to not take and release the GIL every time through.In some cases I also moved uses of _Py_(BEGIN|END)_SUPPRESS_IPH, whichis often paired with Py_(BEGIN|END)_ALLOW_THREADS, to keep the pairingintact. It was already considered safe to call PyErr_CheckSignalsfrom both inside and outside an IPH suppression region.More could be done in this vein: I didn’t change any loops where theinside of the loop was more complicated than a single system call,_except_ that I did refactor py_getentropy and py_getrandom (inbootstrap_hash.c) to make it possible to move the unlock and lockoutside the loop, demonstrating a more complicated case.1 parentc0f5de9 commit3e25a93
File tree
11 files changed
+167
-191
lines changed- Modules
- _io
- _multiprocessing
- Parser
- Python
11 files changed
+167
-191
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
403 | 403 |
| |
404 | 404 |
| |
405 | 405 |
| |
| 406 | + | |
406 | 407 |
| |
407 |
| - | |
408 | 408 |
| |
409 | 409 |
| |
410 | 410 |
| |
411 | 411 |
| |
412 | 412 |
| |
413 |
| - | |
414 | 413 |
| |
415 | 414 |
| |
| 415 | + | |
416 | 416 |
| |
417 | 417 |
| |
418 | 418 |
| |
|
Lines changed: 0 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
647 | 647 |
| |
648 | 648 |
| |
649 | 649 |
| |
650 |
| - | |
651 | 650 |
| |
652 |
| - | |
653 | 651 |
| |
654 | 652 |
| |
655 | 653 |
| |
|
Lines changed: 4 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
57 | 57 |
| |
58 | 58 |
| |
59 | 59 |
| |
| 60 | + | |
60 | 61 |
| |
61 |
| - | |
62 | 62 |
| |
63 |
| - | |
64 | 63 |
| |
| 64 | + | |
65 | 65 |
| |
66 | 66 |
| |
67 | 67 |
| |
| |||
102 | 102 |
| |
103 | 103 |
| |
104 | 104 |
| |
| 105 | + | |
105 | 106 |
| |
106 |
| - | |
107 | 107 |
| |
108 |
| - | |
109 | 108 |
| |
| 109 | + | |
110 | 110 |
| |
111 | 111 |
| |
112 | 112 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
356 | 356 |
| |
357 | 357 |
| |
358 | 358 |
| |
| 359 | + | |
359 | 360 |
| |
360 |
| - | |
361 | 361 |
| |
362 | 362 |
| |
363 | 363 |
| |
364 | 364 |
| |
365 | 365 |
| |
366 | 366 |
| |
367 |
| - | |
368 | 367 |
| |
369 | 368 |
| |
370 | 369 |
| |
371 | 370 |
| |
| 371 | + | |
372 | 372 |
| |
373 | 373 |
| |
374 | 374 |
| |
|
Lines changed: 16 additions & 16 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
73 | 73 |
| |
74 | 74 |
| |
75 | 75 |
| |
| 76 | + | |
76 | 77 |
| |
77 |
| - | |
78 | 78 |
| |
79 |
| - | |
80 | 79 |
| |
| 80 | + | |
81 | 81 |
| |
82 | 82 |
| |
83 | 83 |
| |
| |||
103 | 103 |
| |
104 | 104 |
| |
105 | 105 |
| |
| 106 | + | |
106 | 107 |
| |
107 |
| - | |
108 | 108 |
| |
109 |
| - | |
110 | 109 |
| |
| 110 | + | |
111 | 111 |
| |
112 | 112 |
| |
113 | 113 |
| |
| |||
195 | 195 |
| |
196 | 196 |
| |
197 | 197 |
| |
| 198 | + | |
198 | 199 |
| |
199 |
| - | |
200 | 200 |
| |
201 |
| - | |
202 | 201 |
| |
| 202 | + | |
203 | 203 |
| |
204 | 204 |
| |
205 | 205 |
| |
| |||
219 | 219 |
| |
220 | 220 |
| |
221 | 221 |
| |
| 222 | + | |
222 | 223 |
| |
223 |
| - | |
224 | 224 |
| |
225 |
| - | |
226 | 225 |
| |
| 226 | + | |
227 | 227 |
| |
228 | 228 |
| |
229 | 229 |
| |
| |||
261 | 261 |
| |
262 | 262 |
| |
263 | 263 |
| |
| 264 | + | |
264 | 265 |
| |
265 |
| - | |
266 | 266 |
| |
267 |
| - | |
268 | 267 |
| |
| 268 | + | |
269 | 269 |
| |
270 | 270 |
| |
271 | 271 |
| |
| |||
308 | 308 |
| |
309 | 309 |
| |
310 | 310 |
| |
| 311 | + | |
311 | 312 |
| |
312 |
| - | |
313 | 313 |
| |
314 |
| - | |
315 | 314 |
| |
| 315 | + | |
316 | 316 |
| |
317 | 317 |
| |
318 | 318 |
| |
| |||
335 | 335 |
| |
336 | 336 |
| |
337 | 337 |
| |
| 338 | + | |
338 | 339 |
| |
339 |
| - | |
340 | 340 |
| |
341 |
| - | |
342 | 341 |
| |
| 342 | + | |
343 | 343 |
| |
344 | 344 |
| |
345 | 345 |
| |
| |||
439 | 439 |
| |
440 | 440 |
| |
441 | 441 |
| |
| 442 | + | |
442 | 443 |
| |
443 |
| - | |
444 | 444 |
| |
445 |
| - | |
446 | 445 |
| |
| 446 | + | |
447 | 447 |
| |
448 | 448 |
| |
449 | 449 |
| |
|
0 commit comments
Comments
(0)