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

Method __aexit__

src/crawlee/statistics/_statistics.py:180–201  ·  view source on GitHub ↗

Stop collecting statistics. 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

178 return self
179
180 async def __aexit__(
181 self,
182 exc_type: type[BaseException] | None,
183 exc_value: BaseException | None,
184 exc_traceback: TracebackType | None,
185 ) -> None:
186 """Stop collecting statistics.
187
188 Raises:
189 RuntimeError: If the context manager is not active.
190 """
191 if not self._active:
192 raise RuntimeError(f'The {self.__class__.__name__} is not active.')
193
194 if not self.state.crawler_last_started_at:
195 raise RuntimeError('Statistics.state.crawler_last_started_at not set.')
196
197 # Stop logging and deactivate the statistics to prevent further changes to crawler_runtime
198 await self._periodic_logger.stop()
199 self.state.crawler_finished_at = datetime.now(timezone.utc)
200 self._active = False
201 await self._state.teardown()
202
203 @property
204 def state(self) -> TStatisticsState:

Callers

nothing calls this directly

Calls 2

teardownMethod · 0.80
stopMethod · 0.45

Tested by

no test coverage detected