Commit dfb3467
authored
Enable setting and resetting a thread-local parent header (#1546)
As mentioned in
#1289 (comment)
and #1451, there should be a
public api for setting and clearing a thread-local parent header. This
PR creates a recommended public api for setting/resetting a single
thread's parent without setting the global fallback header. An ipywidget
OutputWidget can use this to temporarily redirect output from a single
thread, for example.
Changelog entry:
> Output from threads can be explicitly routed using the new
`get_ipython().set_thread_parent()`, which also returns a token that can
be used to undo the set with `get_ipython().reset_thread_parent(token)`.
Unlike `set_parent()`, using `set_thread_parent()` does not affect the
default shell parent, so does not affect output routing in other
threads. Since the thread parent is stored in a thread ContextVar,
techniques for propagating a thread's ContextVars will also propagate
the thread parent without having to explicitly call
`set_thread_parent()`.
I also added a number of `x.parent = ...` parent setters to be more
consistent - I'm not directly going to use those, but happy to remove
those if there is an objection.
Claude Fable 5 assisted in this PR4 files changed
Lines changed: 103 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
67 | 80 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 81 | + | |
| 82 | + | |
72 | 83 | | |
73 | 84 | | |
74 | 85 | | |
| |||
88 | 99 | | |
89 | 100 | | |
90 | 101 | | |
| 102 | + | |
91 | 103 | | |
92 | 104 | | |
93 | 105 | | |
| |||
123 | 135 | | |
124 | 136 | | |
125 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
126 | 151 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 152 | + | |
| 153 | + | |
131 | 154 | | |
132 | 155 | | |
133 | 156 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
605 | 605 | | |
606 | 606 | | |
607 | 607 | | |
| 608 | + | |
608 | 609 | | |
609 | | - | |
610 | 610 | | |
611 | 611 | | |
612 | 612 | | |
| |||
632 | 632 | | |
633 | 633 | | |
634 | 634 | | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
635 | 643 | | |
636 | | - | |
| 644 | + | |
637 | 645 | | |
638 | 646 | | |
639 | 647 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
86 | 99 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 100 | + | |
| 101 | + | |
91 | 102 | | |
92 | 103 | | |
93 | 104 | | |
| |||
535 | 546 | | |
536 | 547 | | |
537 | 548 | | |
538 | | - | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
539 | 552 | | |
| 553 | + | |
540 | 554 | | |
541 | 555 | | |
542 | 556 | | |
543 | 557 | | |
544 | 558 | | |
545 | | - | |
546 | 559 | | |
547 | 560 | | |
548 | 561 | | |
| |||
725 | 738 | | |
726 | 739 | | |
727 | 740 | | |
728 | | - | |
729 | 741 | | |
| 742 | + | |
730 | 743 | | |
731 | 744 | | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
| 745 | + | |
737 | 746 | | |
738 | 747 | | |
739 | 748 | | |
| |||
753 | 762 | | |
754 | 763 | | |
755 | 764 | | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
756 | 783 | | |
757 | 784 | | |
758 | 785 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
125 | | - | |
| 124 | + | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
129 | | - | |
| 128 | + | |
| 129 | + | |
130 | 130 | | |
| 131 | + | |
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
137 | | - | |
| 138 | + | |
138 | 139 | | |
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
144 | | - | |
| 145 | + | |
145 | 146 | | |
| 147 | + | |
| 148 | + | |
146 | 149 | | |
147 | 150 | | |
148 | 151 | | |
| |||
151 | 154 | | |
152 | 155 | | |
153 | 156 | | |
| 157 | + | |
| 158 | + | |
154 | 159 | | |
155 | 160 | | |
156 | 161 | | |
| |||
190 | 195 | | |
191 | 196 | | |
192 | 197 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
197 | 201 | | |
198 | 202 | | |
199 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
200 | 212 | | |
201 | 213 | | |
202 | 214 | | |
| |||
220 | 232 | | |
221 | 233 | | |
222 | 234 | | |
223 | | - | |
| 235 | + | |
224 | 236 | | |
225 | 237 | | |
226 | 238 | | |
| |||
0 commit comments