From 5970c05264c65a0bfe8a8532095afe5c1f9c8050 Mon Sep 17 00:00:00 2001 From: Eugenio Lacuesta Date: Sat, 22 Jul 2023 12:59:31 -0300 Subject: [PATCH] await AsyncPlaywright.stop on close --- scrapy_playwright/handler.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scrapy_playwright/handler.py b/scrapy_playwright/handler.py index 6754996..ebe0934 100644 --- a/scrapy_playwright/handler.py +++ b/scrapy_playwright/handler.py @@ -113,8 +113,8 @@ async def _launch(self) -> None: """Launch Playwright manager and configured startup context(s).""" logger.info("Starting download handler") self.playwright_context_manager = PlaywrightContextManager() - playwright_instance = await self.playwright_context_manager.start() - self.browser_type: BrowserType = getattr(playwright_instance, self.browser_type_name) + self.playwright = await self.playwright_context_manager.start() + self.browser_type: BrowserType = getattr(self.playwright, self.browser_type_name) if self.startup_context_kwargs: logger.info("Launching %i startup context(s)", len(self.startup_context_kwargs)) await asyncio.gather( @@ -266,6 +266,7 @@ async def _close(self) -> None: logger.info("Closing browser") await self.browser.close() await self.playwright_context_manager.__aexit__() + await self.playwright.stop() def download_request(self, request: Request, spider: Spider) -> Deferred: if request.meta.get("playwright"):