Skip to content

Commit 807abc6

Browse files
authored
fix: Make contextvars-detection more readable (getsentry#574)
1 parent 85c15e2 commit 807abc6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

sentry_sdk/utils.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -748,12 +748,21 @@ def _get_contextvars():
748748
https://github.com/gevent/gevent/issues/1407
749749
"""
750750
if not _is_threading_local_monkey_patched():
751+
# aiocontextvars is a PyPI package that ensures that the contextvars
752+
# backport (also a PyPI package) works with asyncio under Python 3.6
753+
#
754+
# Import it if available.
755+
if not PY2 and sys.version_info < (3, 7):
756+
try:
757+
from aiocontextvars import ContextVar # noqa
758+
759+
return True, ContextVar
760+
except ImportError:
761+
pass
762+
751763
try:
752764
from contextvars import ContextVar
753765

754-
if not PY2 and sys.version_info < (3, 7):
755-
import aiocontextvars # noqa
756-
757766
return True, ContextVar
758767
except ImportError:
759768
pass

0 commit comments

Comments
 (0)