Bind *kw* to the current thread-local context. Unbind or restore *kw* afterwards. Do **not** affect other keys. Can be used as a context manager or decorator. .. versionadded:: 21.4.0 .. deprecated:: 22.1.0
(**kw: Any)
| 325 | |
| 326 | @contextlib.contextmanager |
| 327 | def bound_threadlocal(**kw: Any) -> Generator[None, None, None]: |
| 328 | """ |
| 329 | Bind *kw* to the current thread-local context. Unbind or restore *kw* |
| 330 | afterwards. Do **not** affect other keys. |
| 331 | |
| 332 | Can be used as a context manager or decorator. |
| 333 | |
| 334 | .. versionadded:: 21.4.0 |
| 335 | .. deprecated:: 22.1.0 |
| 336 | """ |
| 337 | _deprecated() |
| 338 | context = get_threadlocal() |
| 339 | saved = {k: context[k] for k in context.keys() & kw.keys()} |
| 340 | |
| 341 | bind_threadlocal(**kw) |
| 342 | try: |
| 343 | yield |
| 344 | finally: |
| 345 | unbind_threadlocal(*kw.keys()) |
| 346 | bind_threadlocal(**saved) |
| 347 | |
| 348 | |
| 349 | def _get_context() -> Context: |
searching dependent graphs…