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

Method __aenter__

src/crawlee/browsers/_browser_pool.py:202–224  ·  view source on GitHub ↗

Enter the context manager and initialize all browser plugins. Raises: RuntimeError: If the context manager is already active.

(self)

Source from the content-addressed store, hash-verified

200 return self._active
201
202 async def __aenter__(self) -> BrowserPool:
203 """Enter the context manager and initialize all browser plugins.
204
205 Raises:
206 RuntimeError: If the context manager is already active.
207 """
208 if self._active:
209 raise RuntimeError(f'The {self.__class__.__name__} is already active.')
210
211 self._active = True
212 # Start the recurring tasks for identifying and closing inactive browsers
213 self._identify_inactive_browsers_task.start()
214 self._close_inactive_browsers_task.start()
215
216 timeout = self._operation_timeout.total_seconds()
217
218 try:
219 for plugin in self._plugins:
220 await asyncio.wait_for(plugin.__aenter__(), timeout)
221 except asyncio.TimeoutError:
222 logger.warning(f'Initializing of the browser plugin {plugin} timed out, will be skipped.')
223
224 return self
225
226 async def __aexit__(
227 self,

Callers

nothing calls this directly

Calls 1

startMethod · 0.45

Tested by

no test coverage detected