You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2023/11/15 02:34:51 UTC
(airflow) branch main updated: Change terminal mode to cbreak in `execute_interactive` and handle `SIGINT` (#35602)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 24aca11b52 Change terminal mode to cbreak in `execute_interactive` and handle `SIGINT` (#35602)
24aca11b52 is described below
commit 24aca11b5284e39a3b6fba4e13b7609807076f12
Author: Renze Post <re...@gmail.com>
AuthorDate: Wed Nov 15 03:34:43 2023 +0100
Change terminal mode to cbreak in `execute_interactive` and handle `SIGINT` (#35602)
---
airflow/utils/process_utils.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/airflow/utils/process_utils.py b/airflow/utils/process_utils.py
index 6e9bb47d21..15844d9227 100644
--- a/airflow/utils/process_utils.py
+++ b/airflow/utils/process_utils.py
@@ -205,12 +205,12 @@ def execute_interactive(cmd: list[str], **kwargs) -> None:
log.info("Executing cmd: %s", " ".join(shlex.quote(c) for c in cmd))
old_tty = termios.tcgetattr(sys.stdin)
- tty.setraw(sys.stdin.fileno())
+ old_sigint_handler = signal.getsignal(signal.SIGINT)
+ tty.setcbreak(sys.stdin.fileno())
# open pseudo-terminal to interact with subprocess
primary_fd, secondary_fd = pty.openpty()
try:
- # use os.setsid() make it run in a new process group, or bash job control will not be enabled
with subprocess.Popen(
cmd,
stdin=secondary_fd,
@@ -219,6 +219,8 @@ def execute_interactive(cmd: list[str], **kwargs) -> None:
universal_newlines=True,
**kwargs,
) as proc:
+ # ignore SIGINT in the parent process
+ signal.signal(signal.SIGINT, signal.SIG_IGN)
while proc.poll() is None:
readable_fbs, _, _ = select.select([sys.stdin, primary_fd], [], [])
if sys.stdin in readable_fbs:
@@ -230,6 +232,7 @@ def execute_interactive(cmd: list[str], **kwargs) -> None:
os.write(sys.stdout.fileno(), output_data)
finally:
# restore tty settings back
+ signal.signal(signal.SIGINT, old_sigint_handler)
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_tty)