@@ -501,14 +501,8 @@ def spawn(
501501 stop_event : Optional [threading .Event ] = None ,
502502 input_driver : Optional [object ] = None ,
503503 handshake_timeout : float = HANDSHAKE_TIMEOUT_SECONDS ,
504- pre_ack_delay : float = 0.0 ,
505504 ) -> None :
506- """Allocates the terminal, launches the target, and returns once it is running.
507-
508- `pre_ack_delay` holds the parent's acknowledgment for a bounded time. It exists so
509- the barrier's window can be driven deterministically from tests; production
510- callers leave it at zero.
511- """
505+ """Allocates the terminal, launches the target, and returns once it is running."""
512506 if self ._spawned :
513507 raise RuntimeError ("PosixPtyProcess instances are single-use" )
514508 self ._spawned = True
@@ -521,7 +515,7 @@ def spawn(
521515 self ._open_channels ()
522516 self ._start_child (command , cwd , env )
523517 self ._hand_over_to_reader ()
524- self ._run_handshake (deadline , pre_ack_delay )
518+ self ._run_handshake (deadline )
525519 self ._close_owned ("_status_r" ) # the handshake has resolved
526520 except BaseException :
527521 self ._rollback ()
@@ -715,7 +709,7 @@ def _hand_over_to_reader(self) -> None:
715709
716710 # ---------------------------------------------------------------- handshake
717711
718- def _run_handshake (self , deadline : float , pre_ack_delay : float ) -> None :
712+ def _run_handshake (self , deadline : float ) -> None :
719713 parser = _HandshakeParser ()
720714 assert self ._proc is not None and self ._proc .stderr is not None
721715 status_r , err_r = self ._status_r , self ._err_r
@@ -733,12 +727,10 @@ def _run_handshake(self, deadline: float, pre_ack_delay: float) -> None:
733727 watched .discard (stderr_fd )
734728 if err_r in readable :
735729 self ._consume_reader_edge (watched , err_r )
736- if status_r in readable and self ._advance_handshake (parser , status_r , deadline , pre_ack_delay ):
730+ if status_r in readable and self ._advance_handshake (parser , status_r , deadline ):
737731 return
738732
739- def _advance_handshake (
740- self , parser : _HandshakeParser , status_r : int , deadline : float , pre_ack_delay : float
741- ) -> bool :
733+ def _advance_handshake (self , parser : _HandshakeParser , status_r : int , deadline : float ) -> bool :
742734 """Feeds one status chunk. Returns True once exec has been observed."""
743735 chunk = os .read (status_r , READ_CHUNK_BYTES )
744736 try :
@@ -752,17 +744,16 @@ def _advance_handshake(
752744 reason = parser .failure_payload .decode ("utf-8" , "replace" )
753745 raise TerminalLaunchError (self ._launch_message (f"the launcher failed: { reason } " ))
754746 if parser .session_ready and not self ._acked :
755- self ._acknowledge (deadline , pre_ack_delay )
747+ self ._acknowledge (deadline )
756748 return False
757749
758- def _acknowledge (self , deadline : float , pre_ack_delay : float ) -> None :
750+ def _acknowledge (self , deadline : float ) -> None :
759751 """Records the group, delivers the no-driver VEOF, and only then releases the target."""
760752 assert self ._proc is not None
761753 self ._pgid = self ._proc .pid # recorded BEFORE the target can run
762754 if self ._input_driver is None :
763755 self ._inject_veof (deadline )
764- if pre_ack_delay > 0 :
765- self ._wait_pre_ack (pre_ack_delay , deadline )
756+ self ._pre_ack_hook ()
766757 self ._acked = True
767758 ack_w = self ._ack_w
768759 assert ack_w is not None
@@ -774,12 +765,9 @@ def _acknowledge(self, deadline: float, pre_ack_delay: float) -> None:
774765 console .debug ("the launcher closed the acknowledgment pipe before the parent acknowledged" )
775766 self ._close_owned ("_ack_w" )
776767
777- def _wait_pre_ack (self , delay : float , deadline : float ) -> None :
778- until = min (time .monotonic () + delay , deadline )
779- while time .monotonic () < until :
780- self ._check_cancelled ()
781- self ._check_reader_failed ()
782- time .sleep (min (POLL_INTERVAL_SECONDS , max (0.0 , until - time .monotonic ())))
768+ def _pre_ack_hook (self ) -> None :
769+ """The window between the recorded group and the acknowledgment that releases the
770+ target. Empty in production; a test overrides it to hold the window open."""
783771
784772 def _inject_veof (self , deadline : float ) -> None :
785773 result , receipt = self ._input_queue .submit (
0 commit comments