A context manager that freezes the stack trace. AVOID USING THIS CONTEXT MANAGER OUTSIDE OF INTERNAL PYMJCF IMPLEMENTATION, AS IT REDUCES THE USEFULNESS OF DEBUG MODE. If PyMJCF debug mode is enabled, calls to `debugging.get_current_stack_trace` within this context will always return the s
()
| 142 | |
| 143 | @contextlib.contextmanager |
| 144 | def freeze_current_stack_trace(): |
| 145 | """A context manager that freezes the stack trace. |
| 146 | |
| 147 | AVOID USING THIS CONTEXT MANAGER OUTSIDE OF INTERNAL PYMJCF IMPLEMENTATION, |
| 148 | AS IT REDUCES THE USEFULNESS OF DEBUG MODE. |
| 149 | |
| 150 | If PyMJCF debug mode is enabled, calls to `debugging.get_current_stack_trace` |
| 151 | within this context will always return the stack trace from when this context |
| 152 | was entered. |
| 153 | |
| 154 | The frozen stack is global to this debugging module. That is, if the context |
| 155 | is entered while another one is still active, then the stack trace of the |
| 156 | outermost one is returned. |
| 157 | |
| 158 | This context significantly speeds up bulk operations in debug mode, e.g. |
| 159 | parsing an existing XML string or creating a deeply-nested element, as it |
| 160 | prevents the same stack trace from being repeatedly constructed. |
| 161 | |
| 162 | Yields: |
| 163 | `None` |
| 164 | """ |
| 165 | global _CURRENT_FROZEN_STACK |
| 166 | if debug_mode() and _CURRENT_FROZEN_STACK is None: |
| 167 | _CURRENT_FROZEN_STACK = _get_actual_current_stack_trace() |
| 168 | yield |
| 169 | _CURRENT_FROZEN_STACK = None |
| 170 | else: |
| 171 | yield |
| 172 | |
| 173 | |
| 174 | class DebugContext: |
nothing calls this directly
no test coverage detected
searching dependent graphs…