Skip to content

Commit

Permalink
Try even more serious way to hide contextvars from 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgodwin committed Feb 4, 2021
1 parent cc8f04c commit e15ad73
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions asgiref/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import threading
import weakref
from concurrent.futures import Future, ThreadPoolExecutor
from typing import Any, Dict
from typing import Any, Dict, TYPE_CHECKING

from .current_thread_executor import CurrentThreadExecutor
from .local import Local
Expand Down Expand Up @@ -311,9 +311,10 @@ class SyncToAsync:

# Maintain a contextvar for the current execution context. Optionally used
# for thread sensitive mode.
thread_sensitive_context: Any = (
contextvars.ContextVar("thread_sensitive_context") if contextvars else None
)
if not TYPE_CHECKING:
thread_sensitive_context = (
contextvars.ContextVar("thread_sensitive_context") if contextvars else None
)

# Maintaining a weak reference to the context ensures that thread pools are
# erased once the context goes out of scope. This terminates the thread pool.
Expand Down

0 comments on commit e15ad73

Please sign in to comment.