Skip to content
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

--opt in RSGI mode is incompatible with asyncio.timeout #323

Closed
2-5 opened this issue Jun 9, 2024 · 1 comment · Fixed by #452
Closed

--opt in RSGI mode is incompatible with asyncio.timeout #323

2-5 opened this issue Jun 9, 2024 · 1 comment · Fixed by #452
Labels
wontfix This will not be worked on

Comments

@2-5
Copy link
Contributor

2-5 commented Jun 9, 2024

Not sure if this is expected/by-design or not, so I'm reporting it:

import asyncio

async def app(scope, proto):

    async with asyncio.timeout(1):
        await asyncio.sleep(0.1)

    proto.response_str(
        status=200,
        headers=[
            ('content-type', 'text/plain')
        ],
        body=f"Hello, world!"
    )
$ granian --opt --interface rsgi main:app
[ERROR] Application callable raised an exception
Traceback (most recent call last):
  File "main.py", line 5, in app
    async with asyncio.timeout(1):
  File "/usr/lib/python3.11/asyncio/timeouts.py", line 90, in __aenter__
    raise RuntimeError("Timeout should be used inside a task")
RuntimeError: Timeout should be used inside a task

This was quite difficult to track down, maybe a small section could be added to the documentation with a short list of what's known to not work when using --opt

@gi0baro
Copy link
Member

gi0baro commented Jun 10, 2024

@2-5 yeah, I'm sorry about that.
I'm actually considering to just drop the --opt option and related code (maybe after deprecating it for a few releases).
The actual benefits have become more and more questionable with Python 3.11, and almost every real world application out there seems to rely on variables/stuff dropped by those optimizations.

Just for reference, if you move the timeout into a dedicated coro and await such coro in your app it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants