Flask-aiohttp
Flask-aiohttp copied to clipboard
AssertionError: Popped wrong request context
Just tried testing this extension and bumped to this problem. Code is slightly modified "Hello World" variant:
from flask import Flask
from flask.ext.aiohttp import AioHTTP, async
from asyncio import sleep
app = Flask(__name__)
aio = AioHTTP(app)
@app.route('/')
@async
def index():
yield from sleep(3)
return 'Hello world!'
aio.run(app)
Now when I request index page (curl http://localhost:5000), everything goes right - I get Hello world after 3 seconds.
But if I run 2 request simultaneously from different terminals, I get 500 error for both of them. At the same time server prints the following exception twice:
Error handling request
Traceback (most recent call last):
File "/usr/lib/python3.5/site-packages/aiohttp/server.py", line 272, in start
yield from self.handle_request(message, payload)
File "/usr/lib/python3.5/site-packages/aiohttp/web.py", line 85, in handle_request
resp = yield from handler(request)
File "/usr/lib/python3.5/asyncio/coroutines.py", line 202, in coro
res = yield from res
File "/home/mars/test/flask_aiohttp/handler.py", line 18, in __call__
response = yield from self.handle_request(request)
File "/home/mars/test/flask_aiohttp/handler.py", line 119, in handle_request
wsgi_response = yield from iterator
File "/home/mars/test/flask_aiohttp/util.py", line 77, in __call__
rv = yield from rv
File "/usr/lib/python3.5/site-packages/flask/ctx.py", line 386, in __exit__
self.auto_pop(exc_value)
File "/usr/lib/python3.5/site-packages/flask/ctx.py", line 374, in auto_pop
self.pop(exc)
File "/usr/lib/python3.5/site-packages/flask/ctx.py", line 357, in pop
% (rv, self)
AssertionError: Popped wrong request context. (<RequestContext 'http://localhost:5000/hello' [GET] of main> instead of <RequestContext 'http://localhost:5000/hello' [GET] of main>)
What am I doing wrong? I use Python 3.5.0.