FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-105331: Fix asyncio.sleep() bug by weijay0804 · Pull Request #105513 · python/cpython · GitHub

Repository navigation

gh-105331: Fix asyncio.sleep() bug - #105513

Closed
weijay0804 wants to merge 2 commits into
python:mainfrom
weijay0804:fix-issue-105331
Closed

weijay0804 wants to merge 2 commits into
python:mainfrom
weijay0804:fix-issue-105331

Conversation

Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

Comment thread Lib/asyncio/tasks.py
raise TypeError(f"{type(delay)} object cannot be interpreted as an integer")

# According to Modules/timemodule.c
if (delay > sys.maxsize / SEC_TO_NS):

Eclips4 Jun 8, 2023 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It is incorrect because of 32-bit platform (and that's why asyncio test failing on Windows 32-bit).
sys.maxsize on 32-bit platform equal to 2 ** 31 -1.
So, in that case sys.maxsize / SEC_TO_NS is equal to 2.147483647

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Oh!
I forgot about this matter.
In timemodule.c, INT64_MAX is used and is not subject to the limitation of 32-bit.
If I write it as INT64_MAX = 2**64 - 1, how would it be?

if (delay > INT64_MAX / SEC_TO_NS)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Oh! I forgot about this matter. In timemodule.c, INT64_MAX is used and is not subject to the limitation of 32-bit. If I write it as INT64_MAX = 2**64 - 1, how would it be?

if (delay > INT64_MAX / SEC_TO_NS)

I think it's correct solution, but I'm not expert in this area. Let's wait for other opinions

Comment thread Lib/asyncio/tasks.py
if (delay < 0):
raise ValueError("sleep length must be non-negative")

if (math.isnan(delay)):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Also, seems there need to add check that delay is finite number. Use something like if not math.isfinite(delay): ... for resolve that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This appears to be more accurate.

Thank you!

Copy link
Copy Markdown
Member

This PR has some scope creep compared to the issue it purports to fix -- it changes the behavior if the delay is negative. While this was discussed in the issue, no conclusion was drawn (there were conflicting opinions).

If it was just the NaN check I'd approve it after fixing the grammar, punctuation and markup in the NEWS file, but as it is, I can't.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL