99from threading import Thread
1010from typing import TYPE_CHECKING , ClassVar , Self , cast
1111
12- import impit
13-
1412from apify_client ._docs import docs_group
1513
1614if TYPE_CHECKING :
@@ -29,9 +27,8 @@ class StreamedLogBase:
2927 _stream_timeout : ClassVar [Timeout ] = 'no_timeout'
3028 """Timeout for the log-stream long-poll request, which stays open for the whole Actor run.
3129
32- impit applies its `timeout` to the whole request including the streamed body, so any bounded value truncates a
33- longer run mid-stream and raises `impit.TimeoutException` (#1040). `no_timeout` maps to impit's ~24h cap, which
34- is effectively unbounded for real runs and mirrors the JS client.
30+ A bounded transport timeout can truncate a longer run mid-stream. `no_timeout` keeps the connection open for the
31+ duration of the run (Impit currently maps it to an effective 24-hour cap) and mirrors the JS client.
3532 """
3633
3734 def __init__ (self , to_logger : logging .Logger , * , from_start : bool = True ) -> None :
@@ -162,13 +159,13 @@ def _stream_log(self) -> None:
162159 finally :
163160 # Flush the last buffered part even if the read timed out or was stopped.
164161 self ._log_buffer_content (include_last_part = True )
165- except impit . TimeoutException :
166- # With `no_timeout` this fires only if the run outlives impit's ~24h cap or the connection stalls.
167- # The stream cannot continue, so warn and let the thread end instead of leaking a traceback (#1040) .
168- self ._to_logger .warning ('Log streaming stopped: the log stream request timed out.' )
169- except Exception :
170- # Any other failure in log redirection must not escape the background thread; log it instead.
171- self ._to_logger .exception ('Log redirection stopped due to unexpected error:' )
162+ except Exception as exc :
163+ if self . _log_client . _http_client . is_timeout_error ( exc ): # noqa: SLF001
164+ # The stream cannot continue, so warn and let the thread end instead of leaking a traceback.
165+ self ._to_logger .warning ('Log streaming stopped: the log stream request timed out.' )
166+ else :
167+ # Any other failure in log redirection must not escape the background thread; log it instead.
168+ self ._to_logger .exception ('Log redirection stopped due to unexpected error:' )
172169
173170
174171@docs_group ('Other' )
@@ -241,10 +238,10 @@ async def _stream_log(self) -> None:
241238 finally :
242239 # Flush the last buffered part even if the task is cancelled by `stop()`.
243240 self ._log_buffer_content (include_last_part = True )
244- except impit . TimeoutException :
245- # As in `StreamedLog._stream_log`, impit's whole-request timeout on the long-lived stream is an
246- # expected terminal condition, not an error, so log a warning and end the task instead of a traceback .
247- self ._to_logger .warning ('Log streaming stopped: the log stream request timed out.' )
248- except Exception :
249- # Exception in log redirection should not propagate further.
250- self ._to_logger .exception ('Log redirection stopped due to unexpected error:' )
241+ except Exception as exc :
242+ if self . _log_client . _http_client . is_timeout_error ( exc ): # noqa: SLF001
243+ # A timeout on the long-lived stream is an expected terminal condition, not an error .
244+ self ._to_logger .warning ('Log streaming stopped: the log stream request timed out.' )
245+ else :
246+ # Exception in log redirection should not propagate further.
247+ self ._to_logger .exception ('Log redirection stopped due to unexpected error:' )
0 commit comments