Coder Social home page Coder Social logo

aiohttp-asgi's People

Contributors

hugiron avatar kaveshnikov avatar mmasztalerczuk avatar mosquito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

aiohttp-asgi's Issues

Wrong __iter__() implementation

HI! According to pep234 __iter__() must return an iterator object. This method raises StopIteration in the ASGIResource class. It breaks calls like app.router.routes. @mosquito I can make a PR to fix it, if you don't mind.

first example crashes

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

Race with aiohttp main cycle

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:

  1. Set start_response_event to https://github.com/mosquito/aiohttp-asgi/blob/master/aiohttp_asgi/resource.py#L204.
  2. On https://github.com/mosquito/aiohttp-asgi/blob/master/aiohttp_asgi/resource.py#L263, the method is considered completed
  3. On https://github.com/aio-libs/aiohttp/blob/v3.6.2/aiohttp/web_protocol.py#L418, a loop is started
  4. On https://github.com/aio-libs/aiohttp/blob/v3.6.2/aiohttp/web_protocol.py#L462 another 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)

Support aiohttp middlewares

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.