MCPcopy Create free account
hub / github.com/apify/crawlee-python / __aexit__

Method __aexit__

src/crawlee/browsers/_browser_pool.py:226–251  ·  view source on GitHub ↗

Exit the context manager and close all browser plugins. Raises: RuntimeError: If the context manager is not active.

(
        self,
        exc_type: type[BaseException] | None,
        exc_value: BaseException | None,
        exc_traceback: TracebackType | None,
    )

Source from the content-addressed store, hash-verified

224 return self
225
226 async def __aexit__(
227 self,
228 exc_type: type[BaseException] | None,
229 exc_value: BaseException | None,
230 exc_traceback: TracebackType | None,
231 ) -> None:
232 """Exit the context manager and close all browser plugins.
233
234 Raises:
235 RuntimeError: If the context manager is not active.
236 """
237 if not self._active:
238 raise RuntimeError(f'The {self.__class__.__name__} is not active.')
239
240 await self._identify_inactive_browsers_task.stop()
241 await self._close_inactive_browsers_task.stop()
242
243 for browser in self._active_browsers + self._inactive_browsers:
244 await browser.close(force=True)
245 self._active_browsers.clear()
246 self._inactive_browsers.clear()
247
248 for plugin in self._plugins:
249 await plugin.__aexit__(exc_type, exc_value, exc_traceback)
250
251 self._active = False
252
253 @ensure_context
254 async def new_page(

Callers

nothing calls this directly

Calls 3

stopMethod · 0.45
closeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected