MCPcopy Create free account
hub / github.com/hynek/structlog / bound_threadlocal

Function bound_threadlocal

src/structlog/threadlocal.py:327–346  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

325
326@contextlib.contextmanager
327def 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
349def _get_context() -> Context:

Callers 4

test_cleanupMethod · 0.90
test_cleanup_conflictMethod · 0.90
test_nesting_worksMethod · 0.90

Calls 4

_deprecatedFunction · 0.85
get_threadlocalFunction · 0.85
bind_threadlocalFunction · 0.85
unbind_threadlocalFunction · 0.85

Tested by 4

test_cleanupMethod · 0.72
test_cleanup_conflictMethod · 0.72
test_nesting_worksMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…