-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
asyncio.sleep() does not adhere to time.sleep() behavior for negative numbers #83879
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
Python 3.9.0a3+ (heads/master-dirty:f2ee21d858, Feb 19 2020, 23:19:22)
[GCC 9.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.sleep(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: sleep length must be non-negative
>>> import asyncio
>>> async def f():
... await asyncio.sleep(-1)
... print("no exception")
...
>>> asyncio.run(f())
no exception I think that also |
The ship has sailed, this change breaks a lot of existing code without a strong reason. |
Yes. It's a common thing to compute asyncio.sleep delay and sometimes it goes negative. The current behavior is part of our API now. |
Source? |
I see that many breaking changes was done in recent releases. I get only the ones for https://bugs.python.org/issue36921 So I suppose the ship isn't sailed yet. Passing a negative number to a function that should sleep the task for x seconds is a mistake. And mistakes should never pass silently. Furthermore, coherence matters. It's really confusing that two functions in two builtin modules that are quite identical have a different behavior. IMHO, deprecating and then removing support for negative argument in |
I could not find a good source, sorry. I remember I had a complaint in uvloop to support negative timeouts, but I can't trace it. That said, I also distinctly remember seeing code (and writing such code myself) that performs computation on timeouts and does not care if the end value goes below 0. It might be a weak data point but it's still a valid one.
Breaking code/APIs always has a price and we always try to have a very good explanation "why" we want to bother ourselves and users to break backwards compat. This one is not worth it IMHO. We have more breaking API changes that are more substantial coming in future versions of asyncio. So I try to limit the impact by only breaking what's really necessary. |
This is not a good statistics. Frankly we can't measure the impact of the change from these considerations. And furthermore,
Coherence and unhide mistakes are *very* strong points. That said, I'm not so much interested in practice. Do as you wish. The problem is I always considered Python a very elegant programming language, and this behavior is not elegant at all. But, hey, amen. |
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: