Repository navigation
docs: close included page on failure in scrolling example - #404
Open
the-nguyener wants to merge 1 commit into
Open
the-nguyener wants to merge 1 commit into
the-nguyener wants to merge 1 commit into
Conversation
Contributor
|
Aren’t examples simpler than real code on purpose? |
Author
|
Fair point, examples should stay simple. My concern was that this one sets playwright_include_page=True, which makes the page the user's responsibility, and the page closing section of the docs recommends an errback for that. So copying the example leaves a page open if the request times out. I can trim it to just the errback, or I can take the screenshot with a PageMethod instead, so no page handling is needed. Which would you prefer? |
Contributor
|
The PageMethod one, please, like in examples/scroll.py. |
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.
The scrolling example in docs/examples.rst sets playwright_include_page=True but has no errback. If request processing fails, like when wait_for_selector times out, the page is left open during the crawl. The handler skips closing included pages on error, and docs/pages.rst recommends an errback for this case. Unclosed pages count against the page limit and can stall later requests.
This adds a closing errback following the pattern in docs/pages.rst. It also wraps the screenshot in try/finally so the page closes if the screenshot raises.
Validation used static localhost HTML, the real handler, and Chromium with Python 3.12, Scrapy 2.20, and Playwright 1.57. Before the change, request timeout and screenshot failure each left one page open and blocked a follow-up request. After the change, both failure cases and the success control left zero open pages, and all follow-up requests returned HTTP 200 without manual cleanup. The harness drove the handler directly rather than running a full Scrapy crawl.
The docs build, Flake8, and Black pass.