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

Method _dispatch_to_sync

src/structlog/stdlib.py:447–471  ·  view source on GitHub ↗

Merge contextvars and log using the sync logger in a thread pool.

(
        self,
        meth: Callable[..., Any],
        event: str,
        args: tuple[Any, ...],
        kw: dict[str, Any],
    )

Source from the content-addressed store, hash-verified

445
446 # Non-Standard Async
447 async def _dispatch_to_sync(
448 self,
449 meth: Callable[..., Any],
450 event: str,
451 args: tuple[Any, ...],
452 kw: dict[str, Any],
453 ) -> None:
454 """
455 Merge contextvars and log using the sync logger in a thread pool.
456 """
457 # Capture thread-specific info before handing off to the executor.
458 thread_token = _ASYNC_CALLING_THREAD.set(
459 (threading.get_ident(), threading.current_thread().name)
460 )
461 scs_token = _ASYNC_CALLING_STACK.set(sys._getframe().f_back.f_back) # type: ignore[union-attr, arg-type, unused-ignore]
462 ctx = contextvars.copy_context()
463
464 try:
465 await asyncio.get_running_loop().run_in_executor(
466 None,
467 lambda: ctx.run(lambda: meth(event, *args, **kw)),
468 )
469 finally:
470 _ASYNC_CALLING_STACK.reset(scs_token)
471 _ASYNC_CALLING_THREAD.reset(thread_token)
472
473 async def adebug(self, event: str, *args: Any, **kw: Any) -> None:
474 """

Callers 8

adebugMethod · 0.95
ainfoMethod · 0.95
awarningMethod · 0.95
aerrorMethod · 0.95
acriticalMethod · 0.95
afatalMethod · 0.95
aexceptionMethod · 0.95
alogMethod · 0.95

Calls 2

methFunction · 0.85
runMethod · 0.45

Tested by

no test coverage detected