RuntimeError: Timeout context manager should be used inside a task
See original GitHub issueI’m not sure if this is a discord.py problem or an asyncio problem or just an operator error, so if it isn’t discord.py’s problem - my apologies.
dl = asyncio.new_event_loop()
dl.run_until_complete(login())
produces
Traceback (most recent call last):
File "./daemon.py", line 98, in <module>
dl.run_until_complete(login())
File "/usr/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete
return future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
File "./daemon.py", line 92, in login
await client.login(config["token"])
File "/home/zenforic/.local/lib/python3.5/site-packages/discord/client.py", line 416, in login
yield from getattr(self, '_login_' + str(n))(*args, **kwargs)
File "/home/zenforic/.local/lib/python3.5/site-packages/discord/client.py", line 346, in _login_1
data = yield from self.http.static_login(token, bot=is_bot)
File "/home/zenforic/.local/lib/python3.5/site-packages/discord/http.py", line 258, in static_login
data = yield from self.request(Route('GET', '/users/@me'))
File "/home/zenforic/.local/lib/python3.5/site-packages/discord/http.py", line 137, in request
r = yield from self.session.request(method, url, **kwargs)
File "/home/zenforic/.local/lib/python3.5/site-packages/aiohttp/client.py", line 555, in __iter__
resp = yield from self._coro
File "/home/zenforic/.local/lib/python3.5/site-packages/aiohttp/client.py", line 197, in _request
with Timeout(timeout, loop=self._loop):
File "/home/zenforic/.local/lib/python3.5/site-packages/async_timeout/__init__.py", line 36, in __enter__
raise RuntimeError('Timeout context manager should be used '
RuntimeError: Timeout context manager should be used inside a task
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fd967aa0b00>
however, it does not give the error if I use
loop = asyncio.get_event_loop()
loop.run_until_complete(login())
but the problem with that is it blocks the rest of the file, which won’t work.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:12 (1 by maintainers)
Top Results From Across the Web
Timeout context manager should be used inside a task - Stack ...
aiohttp.ClientSession() wants to be called inside a coroutine. Try moving your Client() initializer into any async def function.
Read more >Timeout context manager should be used inside a task · Issue ...
Just today I started having this issue when trying (so far just with SQS) Context i'm calling from inside an aiohttp server request...
Read more >error with request Timeout context manager should be used ...
i cant work out where i am going worng i am in process in moving from an sync to async.
Read more >aio-libs/Lobby - Gitter
Timeout context manager should be used inside a task. I'm accessing aiohttp inside a handler coroutine executed inside asyncio.start_server(). Joongi Kim.
Read more >Timeout context manager should be used inside a task` in ...
[Solved] `RuntimeError: Timeout context manager should be used inside a task` in flask api application. Guest. # testing_scraper_functions.py scraper = Scraper( ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Gorialis I was having this same issue and your comment helped me fix it. For anyone else having this problem, here’s what I did:
The event loop is set when initializing the client, and the separate thread blocks on the same loop. Otherwise, the client attempts to run on the event loop of the thread used to create it (client.py:142).
just use bot.run()
Look at the examples directory, it has plenty of working bots