-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ContextVar support? #3406
Comments
Good point! aiohttp can be modified to create a new contextvar execution context for each web-handler call easily (will work only on Python 3.7 obviously). We need a champion for the issue. |
For now, quick workaround is: @middleware
def fix_middleware(request, handler):
return asyncio.create_task(handler(request))
app = web.Application(middlewares=[fix_middleware]) |
@Reskov thanks for the hint. |
Fixes #3406 A separate task for every request doesn't produce any performance degradation on benchmarks. Tests update is needed to wait not only a task started by connection_made() but also a nexted task.
Long story short
I am trying to check ContextVar integration with aiohttp. https://docs.python.org/3/library/contextvars.html#asyncio-support
ContextVar seems not deals well with aiohttp server... Am I doing something wrong?
Expected behaviour
ContextVar should be different for each request.
Actual behaviour
ContextVar has the same value between requests, but seems to be cleared on failure.
Steps to reproduce
server.py
Other process client.py
Client is working fine, just for example
Response
Server is constantly being failed on each even request.
Extra example
I tried almost the same for
sanic
, and seems that it works fine.Response
Your environment
macOs Mojave
Python 3.7.0 (default, Jun 29 2018, 20:13:13) \n[Clang 9.1.0 (clang-902.0.39.2)]
aiohttp 3.4.4, also tried 3.5.0a1 from master branch
The text was updated successfully, but these errors were encountered: