Repository navigation
gh-105331: Fix asyncio.sleep() bug #105641
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
Changes from 3 commits
f2008da
cb1492f
ca806d9
588bbbd
1c17886
9bd7ced
cc03137
4a08061
11b9d7e
7c3f3eb
730ee4e
49c55c6
c1712ad
5c840c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -642,6 +642,12 @@ def __sleep0(): | |||||
|
|
||||||
| async def sleep(delay, result=None): | ||||||
| """Coroutine that completes after a given time (in seconds).""" | ||||||
|
|
||||||
| # check delay value is not nan | ||||||
| import math | ||||||
| if math.isnan(delay): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this check after |
||||||
| raise ValueError("Invalid value NaN (not a number)") | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion:
Suggested change
|
||||||
|
|
||||||
| if delay <= 0: | ||||||
| await __sleep0() | ||||||
| return result | ||||||
|
|
@@ -944,21 +950,21 @@ def callback(): | |||||
| def create_eager_task_factory(custom_task_constructor): | ||||||
| """Create a function suitable for use as a task factory on an event-loop. | ||||||
|
|
||||||
| Example usage: | ||||||
| Example usage: | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix the indentation change you (accidentally?) applied to much of this docstring. (Maybe your editor inserted tabs instead of spaces?) |
||||||
|
|
||||||
| loop.set_task_factory( | ||||||
| asyncio.create_eager_task_factory(my_task_constructor)) | ||||||
| loop.set_task_factory( | ||||||
| asyncio.create_eager_task_factory(my_task_constructor)) | ||||||
|
|
||||||
| Now, tasks created will be started immediately (rather than being first | ||||||
| scheduled to an event loop). The constructor argument can be any callable | ||||||
| that returns a Task-compatible object and has a signature compatible | ||||||
| with `Task.__init__`; it must have the `eager_start` keyword argument. | ||||||
| Now, tasks created will be started immediately (rather than being first | ||||||
| scheduled to an event loop). The constructor argument can be any callable | ||||||
| that returns a Task-compatible object and has a signature compatible | ||||||
| with `Task.__init__`; it must have the `eager_start` keyword argument. | ||||||
|
|
||||||
| Most applications will use `Task` for `custom_task_constructor` and in | ||||||
| Most applications will use `Task` for `custom_task_constructor` and in | ||||||
| this case there's no need to call `create_eager_task_factory()` | ||||||
| directly. Instead the global `eager_task_factory` instance can be | ||||||
| used. E.g. `loop.set_task_factory(asyncio.eager_task_factory)`. | ||||||
| """ | ||||||
| """ | ||||||
|
|
||||||
| def factory(loop, coro, *, name=None, context=None): | ||||||
| return custom_task_constructor( | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| fix asyncio.sleep(float('nan')) does not raise ValueErro problem | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please try harder here. The text requires proper punctuation, capitalization, markup, and it should describe the change in behavior rather than just stating "fix the problem". |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just move this import to the toplevel, sorted between the rest of the imports.