Repository navigation
fix!: Cancel right away on a zero listener or add-requests timeout #2465
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
base: v2
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -82,7 +82,7 @@ async def wait_for_all_tasks_to_finish( | |
| if not tasks: | ||
| return | ||
|
|
||
| timeout_secs = timeout.total_seconds() if timeout else None | ||
| timeout_secs = timeout.total_seconds() if timeout is not None else None | ||
|
Collaborator
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: Now that zero and ✍️ Drafted by Claude Code |
||
| try: | ||
| _, pending = await asyncio.wait(tasks, timeout=timeout_secs) | ||
| if pending: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| import logging | ||
| from datetime import timedelta | ||
|
|
||
| from crawlee._utils.wait import wait_for_all_tasks_to_finish | ||
|
|
||
|
|
||
| async def test_zero_timeout_cancels_right_away() -> None: | ||
| """A zero timeout cancels the unfinished tasks without waiting for them.""" | ||
| task = asyncio.create_task(asyncio.Event().wait()) | ||
|
|
||
| # Capped, as a zero timeout taken for no limit would wait for the task forever. | ||
| await asyncio.wait_for( | ||
| wait_for_all_tasks_to_finish([task], logger=logging.getLogger(__name__), timeout=timedelta(0)), | ||
| timeout=5, | ||
| ) | ||
|
|
||
| assert task.cancelled() |
Uh oh!
There was an error while loading. Please reload this page.