diff options
author | Erik Johnston <erik@matrix.org> | 2024-06-21 15:32:09 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2024-07-02 16:24:05 +0100 |
commit | 47f157b510de7af640a45aa4527fbb60ba93152f (patch) | |
tree | 8b95c96f26c174a4025f73fd309e1b77492ad1ef /synapse/logging | |
parent | WIP (diff) | |
download | synapse-47f157b510de7af640a45aa4527fbb60ba93152f.tar.xz |
WIP
Diffstat (limited to 'synapse/logging')
-rw-r--r-- | synapse/logging/context.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/synapse/logging/context.py b/synapse/logging/context.py index ec3814f3ae..4b8d6037af 100644 --- a/synapse/logging/context.py +++ b/synapse/logging/context.py @@ -665,14 +665,13 @@ class PreserveLoggingContext: ) -_CURRENT_CONTEXT_VAR: ContextVar[LoggingContextOrSentinel] = ContextVar( - "current_context", default=SENTINEL_CONTEXT -) +_thread_local = threading.local() +_thread_local.current_context = SENTINEL_CONTEXT def current_context() -> LoggingContextOrSentinel: """Get the current logging context from thread local storage""" - return _CURRENT_CONTEXT_VAR.get() + return getattr(_thread_local, "current_context", SENTINEL_CONTEXT) def set_current_context(context: LoggingContextOrSentinel) -> LoggingContextOrSentinel: @@ -693,7 +692,7 @@ def set_current_context(context: LoggingContextOrSentinel) -> LoggingContextOrSe if current is not context: rusage = get_thread_resource_usage() current.stop(rusage) - _CURRENT_CONTEXT_VAR.set(context) + _thread_local.current_context = context context.start(rusage) return current |