@@ -286,16 +286,28 @@ def exit(n: int) -> NoReturn:
286
286
287
287
@attrs .define (kw_only = True )
288
288
class WatchedSubprocess :
289
+ """
290
+ Base class for managing subprocesses in Airflow's TaskSDK.
291
+
292
+ This class handles common functionalities required for subprocess management, such as
293
+ socket handling, process monitoring, and request handling.
294
+ """
295
+
289
296
id : UUID
290
297
291
298
pid : int
299
+ """The process ID of the child process"""
300
+
292
301
stdin : BinaryIO
293
302
"""The handle connected to stdin of the child process"""
294
303
295
304
decoder : TypeAdapter
305
+ """The decoder to use for incoming messages from the child process."""
296
306
297
307
_process : psutil .Process
298
308
_requests_fd : int
309
+ """File descriptor for request handling."""
310
+
299
311
_num_open_sockets : int = 4
300
312
_exit_code : int | None = attrs .field (default = None , init = False )
301
313
@@ -308,7 +320,7 @@ def start(
308
320
logger : FilteringBoundLogger | None = None ,
309
321
** constructor_kwargs ,
310
322
) -> Self :
311
- """Fork and start a new subprocess to execute the given task ."""
323
+ """Fork and start a new subprocess with the specified target function ."""
312
324
# Create socketpairs/"pipes" to connect to the stdin and out from the subprocess
313
325
child_stdin , feed_stdin = mkpipe (remote_read = True )
314
326
child_stdout , read_stdout = mkpipe ()
@@ -538,6 +550,7 @@ def _check_subprocess_exit(self, raise_on_timeout: bool = False) -> int | None:
538
550
@attrs .define (kw_only = True )
539
551
class ActivitySubprocess (WatchedSubprocess ):
540
552
client : Client
553
+ """The HTTP client to use for communication with the API server."""
541
554
542
555
_terminal_state : str | None = attrs .field (default = None , init = False )
543
556
_final_state : str | None = attrs .field (default = None , init = False )
@@ -568,7 +581,8 @@ def start( # type: ignore[override]
568
581
logger : FilteringBoundLogger | None = None ,
569
582
** kwargs ,
570
583
) -> Self :
571
- proc = super ().start (id = what .id , client = client , target = target , logger = logger , ** kwargs )
584
+ """Fork and start a new subprocess to execute the given task."""
585
+ proc : Self = super ().start (id = what .id , client = client , target = target , logger = logger , ** kwargs )
572
586
# Tell the task process what it needs to do!
573
587
proc ._on_child_started (what , path )
574
588
return proc
@@ -908,10 +922,7 @@ def supervise(
908
922
# If we are told to write logs to a file, redirect the task logger to it.
909
923
from airflow .sdk .log import init_log_file , logging_processors
910
924
911
- try :
912
- log_file = init_log_file (log_path )
913
- except OSError as e :
914
- log .warning ("OSError while changing ownership of the log file. " , e )
925
+ log_file = init_log_file (log_path )
915
926
916
927
pretty_logs = False
917
928
if pretty_logs :
0 commit comments