feat: support timeouts in the send_request context helper (#2138) - #2164
Draft
aryansk wants to merge 1 commit into
Draft
feat: support timeouts in the send_request context helper (#2138)#2164aryansk wants to merge 1 commit into
send_request context helper (#2138)#2164aryansk wants to merge 1 commit into
Conversation
Expose the HTTP clients' existing per-request `timeout` support through `SendRequestFunction` so request handlers can bound how long an extra HTTP call may take. Adds a regression test against the slow test-server endpoint.
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.
Closes #2138
Summary
SendRequestFunction(used viacontext.send_request()in request handlers) only acceptedurl,method,payloadandheaders, so a handler could not bound how long an extra HTTP call may take. All four HTTP client implementations (HttpxHttpClient,CurlImpersonateHttpClient,ImpitHttpClient,PlaywrightHttpClient) already support a per-requesttimeout: timedelta | None— this PR just exposes it through the public contract.Changes
src/crawlee/_types.py: addtimeout: timedelta | None = Noneto theSendRequestFunctionprotocol + docstring.src/crawlee/crawlers/_basic/_basic_crawler.py: threadtimeoutthrough the_prepare_send_request_functionclosure intoHttpClient.send_request.tests/unit/crawlers/_basic/test_basic_crawler.py: regression test —context.send_request('/slow?delay=2', timeout=timedelta(milliseconds=100))raisesasyncio.TimeoutError.Validation
pytest tests/unit/crawlers/_basic→ 112 passed, 5 skipped (3.10/3.11-only features)ruff check+ruff format --checkclean on all touched filesNote: no new dependency;
timeoutuses the existingtimedeltaconvention across the Python HTTP clients (the JS implementation names ittimeoutMillis, but the Python clients are timedelta-based).