Fix --wait-for-child-to-exit not working with overlay windows
The issue was a closure problem where the on_child_death callback referenced a responder variable that was created after do_launch() was called. This caused the callback to fail when the child process exited because responder didn't exist in the callback's closure. The fix creates the responder before defining the callback and adds a null check in the callback to ensure it exists before using it. This allows commands like: kitten @ launch --type=overlay --wait-for-child-to-exit bash -c "echo test" to properly wait for the child process to exit and return the exit code.
This commit is contained in:
parent
6020eebea3
commit
9b4bd01148
1 changed files with 7 additions and 2 deletions
|
|
@ -132,6 +132,11 @@ def response_from_kitty(self, boss: Boss, window: Window | None, payload_get: Pa
|
|||
if tabs and tabs[0]:
|
||||
target_tab = tabs[0]
|
||||
|
||||
# Create responder before defining callback to avoid closure issue
|
||||
responder = None
|
||||
if payload_get('wait_for_child_to_exit') and not payload_get('no_response'):
|
||||
responder = self.create_async_responder(payload_get, window)
|
||||
|
||||
def on_child_death(exit_status: int, exc: Exception | None) -> None:
|
||||
code = os.waitstatus_to_exitcode(exit_status)
|
||||
ans = str(code)
|
||||
|
|
@ -141,7 +146,8 @@ def on_child_death(exit_status: int, exc: Exception | None) -> None:
|
|||
ans = Signals(-code).name
|
||||
except ValueError:
|
||||
pass
|
||||
responder.send_data(ans)
|
||||
if responder is not None:
|
||||
responder.send_data(ans)
|
||||
|
||||
w = do_launch(
|
||||
boss, opts, payload_get('args') or [], target_tab=target_tab, rc_from_window=window, base_env=base_env,
|
||||
|
|
@ -152,7 +158,6 @@ def on_child_death(exit_status: int, exc: Exception | None) -> None:
|
|||
if not payload_get('wait_for_child_to_exit'):
|
||||
return str(0 if w is None else w.id)
|
||||
|
||||
responder = self.create_async_responder(payload_get, window)
|
||||
return AsyncResponse()
|
||||
|
||||
def cancel_async_request(self, boss: 'Boss', window: Window | None, payload_get: PayloadGetType) -> None:
|
||||
|
|
|
|||
Loading…
Reference in a new issue