Skip to content
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

trio.sleep(float('nan')) is valid and sleeps forever #2493

Closed
jakkdl opened this issue Dec 1, 2022 · 4 comments · Fixed by #2667
Closed

trio.sleep(float('nan')) is valid and sleeps forever #2493

jakkdl opened this issue Dec 1, 2022 · 4 comments · Fixed by #2667

Comments

@jakkdl
Copy link
Member

jakkdl commented Dec 1, 2022

trio.sleep(float('nan')) currently sleeps forever. Fixing it is pretty trivial by reordering the if statements but there's maybe other stuff that would break with NaN, and it might not be worth fixing a theoretical issue that idk if it might ever happen in reality - though I could imagine it biting somebody somewhere.

for reference: time.sleep() gives a ValueError, asyncio.sleep() sleeps for 0

@Zac-HD
Copy link
Member

Zac-HD commented Mar 16, 2023

I think trio should raise a ValueError, and we should open a CPython issue to do the same in asyncio (if they haven't already considered it on the issue tracker).

@jakkdl
Copy link
Member Author

jakkdl commented Jun 5, 2023

time.sleep and asyncio.sleep do differ in how they handle negative numbers - and changing that was considered a breaking change with no strong reason for changing: python/cpython#83879
So I suspect they'd consider the nan case to be the same.

@jakkdl
Copy link
Member Author

jakkdl commented Jun 5, 2023

fail_after and move_on_after also raises ValueError on negative number - so seems reasonable that they also should error out on getting nan.

But somewhat surprisingly fail_at and move_on_at accept negative number without complaint - they do say the deadline "may be in the past", but a negative number (or nan) feels like it should maybe be treated like an error by them as well?

@oremanj
Copy link
Member

oremanj commented Jun 5, 2023

AFAIK there is nothing to require that the values returned by trio.current_time() be positive, even though they usually are. So we can't forbid absolute deadlines that are below zero.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants