| 200 | """A thread-local stack of context switches.""" |
| 201 | |
| 202 | def __init__(self, eager): |
| 203 | super(_ContextSwitchStack, self).__init__() |
| 204 | self.stack = [] |
| 205 | if eager: |
| 206 | # Initialize the stack with a pointer to enter the eager context; this |
| 207 | # ensures that the fact that eager execution was enabled is propagated |
| 208 | # across threads, since (1) `enable_eager_execution` modifies a |
| 209 | # process-level flag (`default_execution_mode`) and (2) `__init__` is |
| 210 | # called each time a threading.local object is used in a separate thread. |
| 211 | self.push(is_building_function=False, enter_context_fn=eager_mode, |
| 212 | device_stack=None) |
| 213 | |
| 214 | def push(self, is_building_function, enter_context_fn, device_stack): |
| 215 | """Push metadata about a context switch onto the stack. |