summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util/_concurrency_py3k.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/util/_concurrency_py3k.py')
-rw-r--r--lib/sqlalchemy/util/_concurrency_py3k.py19
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