MCPcopy Create free account
hub / github.com/apple/axlearn / install_context_stack

Function install_context_stack

axlearn/common/module.py:574–598  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

572
573
574def 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
583def 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.

Callers 3

_gc_loopMethod · 0.90
_watchdog_loopMethod · 0.90

Calls

no outgoing calls

Tested by 1