diff options
author | Federico Caselli <cfederico87@gmail.com> | 2021-04-01 20:33:53 +0200 |
---|---|---|
committer | Federico Caselli <cfederico87@gmail.com> | 2021-04-01 20:34:39 +0200 |
commit | 508aee203d9ad6beb7bdb83a41b08deae6df0146 (patch) | |
tree | 4ca88f6e02e12ec0cba97f689921e694a9d25810 /lib/sqlalchemy/util/_concurrency_py3k.py | |
parent | 3a29d65f73c6e705f486588068172d45017285fa (diff) | |
download | sqlalchemy-508aee203d9ad6beb7bdb83a41b08deae6df0146.tar.gz |
Prevent loading contextvars in python 3.6
Fixes: #6166
Change-Id: I1355e9a8b6455ca377892214e9426c8f70441f98
Diffstat (limited to 'lib/sqlalchemy/util/_concurrency_py3k.py')
-rw-r--r-- | lib/sqlalchemy/util/_concurrency_py3k.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/sqlalchemy/util/_concurrency_py3k.py b/lib/sqlalchemy/util/_concurrency_py3k.py index 94f4705d8..b905f903b 100644 --- a/lib/sqlalchemy/util/_concurrency_py3k.py +++ b/lib/sqlalchemy/util/_concurrency_py3k.py @@ -6,16 +6,21 @@ from typing import Coroutine import greenlet +from . import compat from .. import exc -try: - from contextvars import copy_context as _copy_context - # If greenlet.gr_context is present in current version of greenlet, - # it will be set with a copy of the current context on creation. - # Refs: https://github.com/python-greenlet/greenlet/pull/198 - getattr(greenlet.greenlet, "gr_context") -except (ImportError, AttributeError): +if compat.py37: + try: + from contextvars import copy_context as _copy_context + + # If greenlet.gr_context is present in current version of greenlet, + # it will be set with a copy of the current context on creation. + # Refs: https://github.com/python-greenlet/greenlet/pull/198 + getattr(greenlet.greenlet, "gr_context") + except (ImportError, AttributeError): + _copy_context = None +else: _copy_context = None |