Repository navigation
Commit 8903f4c
committed
Python runtime: keep waiting log lines in order without spinning
Follow-up to the change that made the bindings' log function stop
running Python code. Lines that cannot go to Python at once wait for
Python's main thread (a pending call) or for a thread of the bindings. A
few cases were wrong:
- The main thread could spin. When some of its lines waited for the
bindings' thread and it logged again with sys.stderr replaced, its
pending call put the lines back and asked to run again at every
bytecode check, until the other thread finished. A Python loop then
ran hundreds of times slower. Now such lines go behind the waiting
ones to the bindings' thread, even if sys.stderr is replaced for a
moment, since keeping the order matters more.
- On the main thread, a binding call that ran in an except block right
after a call that raised wrote its lines before the earlier lines
still waiting for the pending call. Now a call on the main thread
writes those lines first, then its own.
- With fd 2 non-blocking and full, the bindings' thread dropped its
lines when the write returned EAGAIN. Now it waits for room.
- The bindings' thread wrote all its lines in one write, so on a pipe
another thread's line could land inside one of them. Now it writes a
line at a time, which keeps a line of up to PIPE_BUF bytes whole.
- If that thread was still writing to fd 2 when Python finished
exiting, it went back to a thread state Python may have freed. Now it
stops without touching Python once exit has begun, and exit waits
while it takes the GIL back.
The README no longer says that every thread that logs outside a call
hands its line over: only a thread that holds the GIL does, and the list
of hangs that remain now includes the other case.
New tests check the order of the main thread's lines after a call that
raised, that the main thread does not slow down while its lines wait,
and that no line is lost when fd 2 is non-blocking and full.1 parent 87e0d97 commit 8903f4c
3 files changed
Lines changed: 224 additions & 38 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
252 | 254 | | |
253 | 255 | | |
254 | 256 | | |
255 | 257 | | |
256 | 258 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
266 | 271 | | |
267 | 272 | | |
268 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
185 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
186 | 187 | | |
187 | 188 | | |
188 | 189 | | |
| |||
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
225 | 232 | | |
226 | 233 | | |
227 | 234 | | |
| |||
389 | 396 | | |
390 | 397 | | |
391 | 398 | | |
392 | | - | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
393 | 413 | | |
394 | 414 | | |
395 | 415 | | |
| |||
431 | 451 | | |
432 | 452 | | |
433 | 453 | | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
434 | 481 | | |
435 | 482 | | |
436 | | - | |
437 | | - | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
438 | 486 | | |
439 | 487 | | |
440 | 488 | | |
| |||
444 | 492 | | |
445 | 493 | | |
446 | 494 | | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
| 495 | + | |
| 496 | + | |
452 | 497 | | |
| 498 | + | |
| 499 | + | |
453 | 500 | | |
454 | 501 | | |
455 | 502 | | |
| |||
476 | 523 | | |
477 | 524 | | |
478 | 525 | | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
487 | 536 | | |
488 | 537 | | |
489 | 538 | | |
| |||
508 | 557 | | |
509 | 558 | | |
510 | 559 | | |
511 | | - | |
| 560 | + | |
| 561 | + | |
512 | 562 | | |
| 563 | + | |
513 | 564 | | |
514 | 565 | | |
515 | 566 | | |
| |||
539 | 590 | | |
540 | 591 | | |
541 | 592 | | |
| 593 | + | |
| 594 | + | |
542 | 595 | | |
543 | 596 | | |
544 | 597 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
707 | 707 | | |
708 | 708 | | |
709 | 709 | | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
710 | 732 | | |
711 | 733 | | |
712 | 734 | | |
| |||
729 | 751 | | |
730 | 752 | | |
731 | 753 | | |
| 754 | + | |
732 | 755 | | |
733 | 756 | | |
734 | 757 | | |
| |||
744 | 767 | | |
745 | 768 | | |
746 | 769 | | |
747 | | - | |
748 | | - | |
| 770 | + | |
| 771 | + | |
749 | 772 | | |
750 | 773 | | |
751 | 774 | | |
| |||
1076 | 1099 | | |
1077 | 1100 | | |
1078 | 1101 | | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
1079 | 1207 | | |
1080 | 1208 | | |
1081 | 1209 | | |
| |||
0 commit comments