forked from orbit-oss/flask
Raise a runtime error if run_async is called without real ContextVars
Werkzeug offers a ContextVar replacement for Python < 3.7, however it doesn't work across asyncio tasks, hence it makes sense to error out rather than find there are odd bugs. Note the docs build requires the latest (dev) Werkzeug due to this change (to import ContextVar from werkzeug.local).
This commit is contained in:
parent
6979265fa6
commit
c6c6408c3f
3 changed files with 19 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ from threading import RLock
|
|||
|
||||
import werkzeug.utils
|
||||
from werkzeug.exceptions import NotFound
|
||||
from werkzeug.local import ContextVar
|
||||
from werkzeug.routing import BuildError
|
||||
from werkzeug.urls import url_quote
|
||||
|
||||
|
|
@ -741,6 +742,11 @@ def run_async(func):
|
|||
"Install Flask with the 'async' extra in order to use async views."
|
||||
)
|
||||
|
||||
if ContextVar.__module__ == "werkzeug.local":
|
||||
raise RuntimeError(
|
||||
"async cannot be used with this combination of Python & Greenlet versions"
|
||||
)
|
||||
|
||||
@wraps(func)
|
||||
def outer(*args, **kwargs):
|
||||
"""This function grabs the current context for the inner function.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue