fix(xhs): let Ctrl+C stop the crawl instead of being retried - #982
Open
ChrisDoufu wants to merge 1 commit into
Open
ChrisDoufu wants to merge 1 commit into
ChrisDoufu wants to merge 1 commit into
Conversation
The tenacity retry on request() and get_note_by_id_from_html() retries every exception except a listed few, and asyncio.CancelledError was not among them. Pressing Ctrl+C cancelled the task, tenacity caught the CancelledError and sent the request again, and in the note path the final RetryError was swallowed, so the crawl kept running. CancelledError is now excluded from retries. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This branch has not been deployed
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
The Xiaohongshu client uses tenacity to retry a request that fails.
request()andget_note_by_id_from_html()retry on all exceptions, except the exceptions in a list.asyncio.CancelledErroris not in that list.Problem
Ctrl+C does not stop the crawl.
CancelledError.RetryError.get_note_detail_async_task()catchesRetryErrorand continues with the HTML fallback.Thus, the crawl continues after Ctrl+C.
Change
Add
asyncio.CancelledErrorto the list of exceptions that tenacity does not retry. The change is inrequest()and inget_note_by_id_from_html(). Now Ctrl+C stops the crawl immediately.Test
tests/test_xhs_raw_response_errors.py::test_ctrl_c_is_not_retriedmakes the HTTP client raiseCancelledError. The test makes sure thatrequest()raisesCancelledErrorafter one attempt. The test fails before this change and passes after it. All 12 tests in the file pass.🤖 Generated with Claude Code