-
Notifications
You must be signed in to change notification settings - Fork 552
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
uvloop + aiohttp RuntimeError: Timeout context manager should be used inside a task #63
Comments
This is strange, I don't see how this can happen. Could you please share the code so that I can debug this? |
Finally I figure it out, it is caused by the incorrect position of installing code. The installing code is put under one imported module which creates an instance of # main.py
import asyncio
from foo import Foo
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
async def fetch(url):
foo = Foo()
async with foo.session.get(url) as resp:
# RuntimeError will be raised here
pass
loop = asyncio.get_event_loop()
loop.run_until_complete(fetch('http://example.com'))
# foo.py
import aiohttp
class Foo():
session = aiohttp.ClientSession() # to share session between instances of Foo |
Hrrr. You are creating a global var here (class variable actually). |
I have to admit that it is a bad idea. And will remove these lazy code. Thanks! |
Should this issue be closed now? |
OK, closing this. |
Hi guys,
My program runs normally when using default asyncio policy. But if installing the uvloop event loop policy,
the following exception will be raised:
Thanks!
The text was updated successfully, but these errors were encountered: