remove ContextVar compat
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent e609ddd · Browse files · 6 files·+22 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+22 added−13 removed
- other:+22 added−13 removed
Provenance
- Commit
1b552d0- Tree
fe7de6a- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
e609ddd
6 files changed+22 added−13 removed
modified:docs/async-await.rst+7 added-2 removed
5 unmodified lines6 .. versionadded:: 2.07 8 Routes, error handlers, before request, after request, and teardown9 functions can all be coroutine functions if Flask is installed with the10-``async`` extra (``pip install flask[async]``). It requires Python 3.7+11-where ``contextvars.ContextVar`` is available. This allows views to be10+``async`` extra (``pip install flask[async]``). This allows views to be11 defined with ``async def`` and use ``await``.12 13 .. code-block:: python14 13 unmodified lines28 Python 3.8 has a bug related to asyncio on Windows. If you encounter29 something like ``ValueError: set_wakeup_fd only works in main thread``,30 please upgrade to Python 3.9.31 32+.. admonition:: Using ``async`` with greenlet33 34+ When using gevent or eventlet to serve an application or patch the35+ runtime, greenlet>=1.0 is required. When using PyPy, PyPy>=7.3.7 is36+ required.37+38+39 Performance40 -----------41 42 Async functions require an event loop to run. Flask, as a WSGI89 unmodified linesmodified:docs/installation.rst+12 added
47 unmodified lines48 .. _python-dotenv: https://github.com/theskumar/python-dotenv#readme49 .. _watchdog: https://pythonhosted.org/watchdog/50 51 52+greenlet53+~~~~~~~~54+55+You may choose to use gevent or eventlet with your application. In this56+case, greenlet>=1.0 is required. When using PyPy, PyPy>=7.3.7 is57+required.58+59+These are not minimum supported versions, they only indicate the first60+versions that added necessary features. You should use the latest61+versions of each.62+63+64 Virtual environments65 --------------------66 67 Use a virtual environment to manage the dependencies for your project, both in78 unmodified linesmodified:requirements/dev.txt+1 added-1 removed
36 unmodified lines37 filelock==3.3.238 # via39 # tox40 # virtualenv41-greenlet==1.1.241+greenlet==1.1.2 ; python_version < "3.11"42 # via -r requirements/tests.in43 identify==2.3.344 # via pre-commit45 idna==3.3118 unmodified linesmodified:requirements/tests.in+1 added-1 removed
1 pytest2 asgiref3 blinker4-greenlet4+greenlet ; python_version < "3.11"5 python-dotenvmodified:requirements/tests.txt+1 added-1 removed
8 unmodified lines9 attrs==21.2.010 # via pytest11 blinker==1.412 # via -r requirements/tests.in13-greenlet==1.1.213+greenlet==1.1.2 ; python_version < "3.11"14 # via -r requirements/tests.in15 iniconfig==1.1.116 # via pytest17 packaging==21.213 unmodified linesmodified:src/flask/app.py-8 removed
14 unmodified lines15 from werkzeug.exceptions import BadRequest16 from werkzeug.exceptions import BadRequestKeyError17 from werkzeug.exceptions import HTTPException18 from werkzeug.exceptions import InternalServerError19-from werkzeug.local import ContextVar19 from werkzeug.routing import BuildError20 from werkzeug.routing import Map21 from werkzeug.routing import MapAdapter22 from werkzeug.routing import RequestRedirect1596 unmodified lines1619 raise RuntimeError(1620 "Install Flask with the 'async' extra in order to use async views."1621 ) from None1622 1624- # Check that Werkzeug isn't using its fallback ContextVar class.1625- if ContextVar.__module__ == "werkzeug.local":1626- raise RuntimeError(1627- "Async cannot be used with this combination of Python "1628- "and Greenlet versions."1629- )1630-1623 return asgiref_async_to_sync(func)1624 1625 def make_response(self, rv: ResponseReturnValue) -> Response:1626 """Convert the return value from a view function to an instance of457 unmodified lines