-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
wait_for(gather(...)) logs weird error message #73618
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
Comments
when waiting for a gather that times out, everything works as expected, yet a weird error message is logged. To give a minimal example: import asyncio
@asyncio.coroutine
def main():
try:
sleep = asyncio.sleep(0.2)
yield from asyncio.wait_for(asyncio.gather(sleep),
timeout=0.1)
except asyncio.TimeoutError:
print("timed out: fine")
yield from asyncio.sleep(0.1)
This outputs:
As you can see, I used the pre-3.5 syntax so I could test whether it works on older systems. No, it doesn't. I wrote a unit test for this problem, unfortunately I couldn't solve it yet. |
I added a solution to this problem. I just silence the bad error message by overwriting _GatheringFuture.__del__ to do nothing. This may have undesired side effects, though. |
I noticed that the future defined by asyncio.gather(sleep) is in a "pending" state immediately after the asyncio.TimeoutError. One workaround is to wait for the cancellation to finish: @asyncio.coroutine
def main():
sleep = asyncio.sleep(0.2)
future = asyncio.gather(sleep)
try:
yield from asyncio.wait_for(future, timeout=0.1)
except asyncio.TimeoutError:
print(f'future: {future}')
try:
yield from future
except asyncio.CancelledError:
print(f'future: {future}')
yield from asyncio.sleep(0.1)
Outputs:
Another option is to pass return_exceptions=True to gather(). This appears to make the log messages you were concerned about go away:
|
By the way, I see this exact issue was also raised and discussed here, with a couple responses by Guido, too: |
it looks like this was fixed in python 3.9:
|
looks like it was fixed by this https://github.com/python/cpython/pull/20054/files#diff-429f4ed1e0f89ea2c92e2a8e8548ea8ae1a3d528979554fbfa4c38329e951529R503 |
Happy to close it. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: