mosquito / aiohttp-asgi Goto Github PK
View Code? Open in Web Editor NEWRun ASGI application with aiohttp
License: Other
Run ASGI application with aiohttp
License: Other
Greetings,
I have a question.
aiohttp=3.6.2, aiohttp_asgi=0.3.1
When I try to send a certain piece of data >170 Kb, I get a lot of errors like
line 78, in _drain_helper
assert waiter is None or waiter.cancelled()
I've done a little and hopefully correct investigation, and it looks like ASGIContext
should consider the get_response
method to have completed recently.
The current behaviour is as follows:
start_response_event
to https://github.com/mosquito/aiohttp-asgi/blob/master/aiohttp_asgi/resource.py#L204.write
+ drain
is called.Currently, aiohttp doesn't wait until we've sent all our data.
However, I'm not sure if I'm using the library correctly. Could you please confirm or refute my assumptions. If I'm wrong somewhere, how should I proceed in my case?
To reproduce:
async def f(scope, receive, send):
if payload.get("type") == "http.request":
data = 'a' * 65600 * 1024
await send(
{
"type": "http.response.start",
"status": 200,
"headers": []
}
)
await send({"type": "http.response.body", "body": data.encode()})
new_res = aiohttp_asgi.ASGIResource(f, root_path='/test')
app.router.register_resource(new_res)
Hi! Are you going to support aiohttp middlewares?
I tried to use this lib with aiohttp.web.normalize_path_middleware() and got an exception: ASGIMatchInfo' object has no attribute 'set_current_app'
. This happened because of this call.
aiohttp==3.6.2
aiohttp-asgi==0.2.0
I ran the first README.md
example exactly as-is, and it crashed with this traceback (on Ubuntu, but also crashes with similar error on Windows 10)
python example1.py
unhandled exception during asyncio.run() shutdown
task: <Task finished name='Task-2' coro=<_run_app() done, defined at /mnt/c/Users/jeff1/Documents/projects/git/aio-test-u/.venv/lib/python3.9/site-packages/aiohttp/web.py:289> exception=RuntimeError("Task <Task pending name='Task-2' coro=<_run_app() running at /mnt/c/Users/jeff1/Documents/projects/git/aio-test-u/.venv/lib/python3.9/site-packages/aiohttp/web.py:323> cb=[_run_until_complete_cb() at /home/jeff1/.pyenv/versions/3.9.13/lib/python3.9/asyncio/base_events.py:184]> got Future <Future pending> attached to a different loop")>
Traceback (most recent call last):
File "aio-test-u/.venv/lib/python3.9/site-packages/aiohttp/web.py", line 516, in run_app
loop.run_until_complete(main_task)
File "/home/jeff1/.pyenv/versions/3.9.13/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
return future.result()
File "aio-test-u/.venv/lib/python3.9/site-packages/aiohttp/web.py", line 323, in _run_app
await runner.setup()
File "aio-test-u/.venv/lib/python3.9/site-packages/aiohttp/web_runner.py", line 279, in setup
self._server = await self._make_server()
File "aio-test-u/.venv/lib/python3.9/site-packages/aiohttp/web_runner.py", line 375, in _make_server
await self._app.startup()
File "aio-test-u/.venv/lib/python3.9/site-packages/aiohttp/web_app.py", line 417, in startup
await self.on_startup.send(self)
File "aio-test-u/.venv/lib/python3.9/site-packages/aiosignal/__init__.py", line 36, in send
await receiver(*args, **kwargs) # type: ignore
File "aio-test-u/.venv/lib/python3.9/site-packages/aiohttp_asgi/resource.py", line 337, in on_startup
msg = await sends.get()
File "/home/jeff1/.pyenv/versions/3.9.13/lib/python3.9/asyncio/queues.py", line 166, in get
await getter
RuntimeError: Task <Task pending name='Task-2' coro=<_run_app() running at aio-test-u/.venv/lib/python3.9/site-packages/aiohttp/web.py:323> cb=[_run_until_complete_cb() at /home/jeff1/.pyenv/versions/3.9.13/lib/python3.9/asyncio/base_events.py:184]> got Future <Future pending> attached to a different loop
Traceback (most recent call last):
File "aio-test-u/example1.py", line 42, in <module>
web.run_app(aiohttp_app)
File "aio-test-u/.venv/lib/python3.9/site-packages/aiohttp/web.py", line 516, in run_app
loop.run_until_complete(main_task)
File "/home/jeff1/.pyenv/versions/3.9.13/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
return future.result()
File "aio-test-u/.venv/lib/python3.9/site-packages/aiohttp/web.py", line 323, in _run_app
await runner.setup()
File "aio-test-u/.venv/lib/python3.9/site-packages/aiohttp/web_runner.py", line 279, in setup
self._server = await self._make_server()
File "aio-test-u/.venv/lib/python3.9/site-packages/aiohttp/web_runner.py", line 375, in _make_server
await self._app.startup()
File "aio-test-u/.venv/lib/python3.9/site-packages/aiohttp/web_app.py", line 417, in startup
await self.on_startup.send(self)
File "aio-test-u/.venv/lib/python3.9/site-packages/aiosignal/__init__.py", line 36, in send
await receiver(*args, **kwargs) # type: ignore
File "aio-test-u/.venv/lib/python3.9/site-packages/aiohttp_asgi/resource.py", line 337, in on_startup
msg = await sends.get()
File "/home/jeff1/.pyenv/versions/3.9.13/lib/python3.9/asyncio/queues.py", line 166, in get
await getter
RuntimeError: Task <Task pending name='Task-2' coro=<_run_app() running at aio-test-u/.venv/lib/python3.9/site-packages/aiohttp/web.py:323> cb=[_run_until_complete_cb() at /home/jeff1/.pyenv/versions/3.9.13/lib/python3.9/asyncio/base_events.py:184]> got Future <Future pending> attached to a different loop
Task was destroyed but it is pending!
task: <Task pending name='Task-1' coro=<FastAPI.__call__() running at aio-test-u/.venv/lib/python3.9/site-packages/fastapi/applications.py:267>>
sys:1: RuntimeWarning: coroutine 'FastAPI.__call__' was never awaited
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.