diff --git a/pyproject.toml b/pyproject.toml index c2d7fde4..b5a87634 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ classifiers = [ keywords = ["apify", "api", "client", "automation", "crawling", "scraping"] dependencies = [ "colorama>=0.4.0", - "impit>=0.9.2", + "impit~=0.12.0", "more_itertools>=10.0.0", "pydantic[email]>=2.11.0", ] diff --git a/src/apify_client/_streamed_log.py b/src/apify_client/_streamed_log.py index 92178e9a..3e693e2c 100644 --- a/src/apify_client/_streamed_log.py +++ b/src/apify_client/_streamed_log.py @@ -215,12 +215,16 @@ async def __aexit__( await self.stop() async def _stream_log(self) -> None: - async with self._log_client.stream(raw=True) as log_stream: - if not log_stream: - return - try: - async for data in log_stream.aiter_bytes(): - self._process_new_data(data) - finally: - # Flush the last buffered part even if the task is cancelled by `stop()`. - self._log_buffer_content(include_last_part=True) + try: + async with self._log_client.stream(raw=True) as log_stream: + if not log_stream: + return + try: + async for data in log_stream.aiter_bytes(): + self._process_new_data(data) + finally: + # Flush the last buffered part even if the task is cancelled by `stop()`. + self._log_buffer_content(include_last_part=True) + except Exception: + # Exception in log redirection should not propagate further. + self._to_logger.exception('Log redirection stopped due to unexpected error:') diff --git a/uv.lock b/uv.lock index ddb2d792..a584970d 100644 --- a/uv.lock +++ b/uv.lock @@ -74,7 +74,7 @@ dev = [ [package.metadata] requires-dist = [ { name = "colorama", specifier = ">=0.4.0" }, - { name = "impit", specifier = ">=0.9.2" }, + { name = "impit", specifier = "~=0.12.0" }, { name = "more-itertools", specifier = ">=10.0.0" }, { name = "pydantic", extras = ["email"], specifier = ">=2.11.0" }, ]