Python concurrent futures base timeouterror

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

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

Handle all concurrent.futures._base.TimeoutError and throw a aiohttp.errors.TimeoutError instead. #1207

Handle all concurrent.futures._base.TimeoutError and throw a aiohttp.errors.TimeoutError instead. #1207

Comments

Long story short

This is better to explain with the full Traceback:

Ignoring exception caused at _resolve_edit_method_code: Traceback (most recent call last): File "E:\Users\Elsword\Desktop\DecoraterBot\Async\\resources\Dependencies\DecoraterBotCore\Ignore.py", line 630, in resolve_edit_method_code yield from DBLogs.send_edit_logs(client, before, after) File "E:\Users\Elsword\Desktop\DecoraterBot\Async\\resources\Dependencies\DecoraterBotCore\BotLogs.py", line 523, in send_edit_logs yield from self.bot.send_edit_logs_code(client, before, after) File "E:\Users\Elsword\Desktop\DecoraterBot\Async\\resources\Dependencies\DecoraterBotCore\BotLogs.py", line 263, in send_edit_logs_code yield from client.send_message(discord.Object(id='153055192873566208'), sendeditlogs) File "discord\client.py", line 834, in send_message File "discord\http.py", line 105, in request File "E:\Users\Elsword\Desktop\DecoraterBot\Async\\resources\Dependencies\win32-deps\3.5\aiohttp\client.py", line 555, in __iter__ resp = yield from self._coro File "E:\Users\Elsword\Desktop\DecoraterBot\Async\\resources\Dependencies\win32-deps\3.5\aiohttp\client.py", line 198, in _request conn = yield from self._connector.connect(req) File "async_timeout\__init__.py", line 44, in __exit__ concurrent.futures._base.TimeoutError

Expected behaviour

To Throw a aiohttp.errors.TimeoutError instead of a concurrent.futures._base.TimeoutError on
File «aiohttp\client.py», line 198, in _request conn = yield from self._connector.connect(req)

Читайте также:  Mime content type css

Actual behaviour

Line 198 thows a concurrent.futures._base.TimeoutError making it hard to handle if you do not want to import concurrent just to handle the exceptions from it.

Steps to reproduce

Something that used to exist but does not anymore so when it tries to connect for x time it throws this.

Your environment

Windows 7 Ultimate x64
Python 3.5.2 (embedded) (I Insalled aiohttp (latest 1.0.2) with a installed version but use the embedded one because I can 😛 )

The text was updated successfully, but these errors were encountered:

Источник

How to catch concurrent.futures._base.TimeoutError correctly when using asyncio.wait_for and asyncio.Semaphore?

First of all, i need to warn you: I’m new to asyncio, and i h I warn you right away, I’m new to asyncio, and I can hardly imagine what is in the library under the hood. Here is my code:

import asyncio semaphore = asyncio.Semaphore(50) async def work(value): async with semaphore: print(value) await asyncio.sleep(10) async def main(): tasks = [] for i in range(0, 10000): tasks.append(asyncio.wait_for(work(i), timeout=3)) await asyncio.gather(*tasks) loop = asyncio.get_event_loop() future = asyncio.ensure_future(main()) loop.run_until_complete(future) 

What i need: Coroutine work() to be completed for no more than 3 seconds, and no more than 50 pieces at a same time. After 3 seconds (timeout), the coroutine work() must stop execution, and a new 50 tasks must start to work. But in my case, after 3 seconds crashes:

Traceback (most recent call last): File "C:/Users/root/PycharmProjects/LogParser/ssh/async/asyn_test.py", line 19, in loop.run_until_complete(future) File "C:\Code\Python3\lib\asyncio\base_events.py", line 579, in run_until_complete return future.result() File "C:/Users/root/PycharmProjects/LogParser/ssh/async/asyn_test.py", line 15, in main await asyncio.gather(*tasks) File "C:\Code\Python3\lib\asyncio\tasks.py", line 449, in wait_for raise futures.TimeoutError() concurrent.futures._base.TimeoutError 

Whatever I had not tried to catch this exception, no matter how many tasks remained, program breaks down. I need, upon reaching timeout, the program continued to the next tasks Please, teach me, how do I need properly implement this? Python 3.7, asyncio 3.4.3

Источник

How to catch concurrent.futures._base.TimeoutError

I’m trying to catch exception thrown inside a run_until_complete but whatever I try, I can’t seems to catch them properly. Here’s my latest attempt (note, I’m using Pypputeer, a fork of Puppeteer in Python, that uses asyncio):

import asyncio from pyppeteer.launcher import launch async def test(instance): page = await instance.newPage() await page.goto('http://www.google.com', ) await page.pdf() async def test2(): instance = launch(headless=True) try: task = asyncio.ensure_future(test(instance)) print(task) await task except: print("Caught!") instance.close() def __main__(): try: loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) loop.run_until_complete(test2()) except: print("ERROR") return 'ok' 
Exception in callback NavigatorWatcher.waitForNavigation..watchdog_cb( result=None>) at /home/user/www/project/api/env/lib/python3.6/site-packages/pyppeteer/navigator_watcher.py:49 handle: ) at /home/user/www/project/api/env/lib/python3.6/site-packages/pyppeteer/navigator_watcher.py:49> Traceback (most recent call last): File "/usr/lib64/python3.6/asyncio/events.py", line 145, in _run self._callback(*self._args) File "/home/user/www/project/api/env/lib/python3.6/site-packages/pyppeteer/navigator_watcher.py", line 52, in watchdog_cb self._timeout) File "/home/user/www/project/api/env/lib/python3.6/site-packages/pyppeteer/navigator_watcher.py", line 40, in _raise_error raise error concurrent.futures._base.TimeoutError: Navigation Timeout Exceeded: 1 ms exceeded 

So, TLDR, how can I catch exceptions thrown inside a run_until_complete call of asyncio?

Источник

Оцените статью