Installs the given context stack. `install_context_stack` should be called in every child thread to ensure that each thread uses its own context stack: ``` def my_thread(context_stack): install_context_stack(context_stack) ... t = Thread(target=my_thread, kwarg
(stack: list[InvocationContext])
| 572 | |
| 573 | |
| 574 | def clone_context_stack() -> list[InvocationContext]: # pytype: disable=invalid-annotation |
| 575 | """Returns a copy of the current InvocationContext stack. |
| 576 | |
| 577 | This is often used together with `install_context_stack` to ensure that different threads |
| 578 | do not interfere with each other. See `install_context_stack`. |
| 579 | """ |
| 580 | return list(_global_context_stack.stack) |
| 581 | |
| 582 | |
| 583 | def install_context_stack(stack: list[InvocationContext]): # pytype: disable=invalid-annotation |
| 584 | """Installs the given context stack. |
| 585 | |
| 586 | `install_context_stack` should be called in every child thread to ensure that each thread |
| 587 | uses its own context stack: |
| 588 | |
| 589 | ``` |
| 590 | def my_thread(context_stack): |
| 591 | install_context_stack(context_stack) |
| 592 | ... |
| 593 | |
| 594 | t = Thread(target=my_thread, kwargs=dict(context_stack=clone_context_stack())) |
| 595 | ``` |
| 596 | |
| 597 | Args: |
| 598 | stack: The context stack to install. This is usually returned by `clone_context_stack()`. |
| 599 | |
| 600 | Raises: |
| 601 | ValueError: if the current thread id does not match the global context stack thread id. |
no outgoing calls