-
Notifications
You must be signed in to change notification settings - Fork 14.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change terminal mode to cbreak in execute_interactive
and handle SIGINT
#35602
Conversation
Nice. Looks pretty resonable. World of low-level terminal interfaces is pretty intriguing It's an interesting though why you need to send the signal to proc? It think we should simply ignore the signal rather than send it to the spawned process. From what I understand how the Ctrl-C works is that it sends the signal to process group rather than to the main process. When we create the child process (despite a comment - see below) it does not look like the process is created with a "create new process group" flag - so Ctrl-C should also be sent to the child process. Of course we still do not want KeyboardInterupt Exception as you noticed, so I'd say we could likely ignore the signal rather than send it to the new process - otherwise the process will receive two signals one after the other. Re the comment: we have this comment there:
So it looks like at least at some point of time there was a new process group created when spawning the process, but you cannot see it anywhere in the code. So maybe we shoudl also remove the comment while we are at it. So I'd say just ignoring the signal would be a better approach. |
Also one more comment here - when we set the signal to a new handler (or ignore which is equivalent), we should - at least in theory, save the previous handler and restore it in the finally clause. It does not matter likely in this case - because we are going to exit the |
8ea6f88
to
fa9dcf3
Compare
Hi Jarek, You were absolutely right! The subprocess has the same PGID, so I made some changes. Now the calling process simply ignores the SIGINT. I tested this with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool ! Thanks for being responsive here :)!
LGTM
Related: #26186
Because the terminal mode was set to raw mode,
Ctrl-C
was not being interpreted as aSIGINT
signal. Changing to cbreak mode will maintain most of the features of raw mode, except that keystrokes likeCtrl-C
will be interpreted by the terminal and will interrupt.Besides that, a handler for
SIGINT
is added so that the signal is simply passed to the subprocess (instead of causing a KeyboardInterrupt.)This at least partially fixes #26186, because now hitting Ctrl-C will cause psql (and mysql) to interrupt any partial input.
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rst
or{issue_number}.significant.rst
, in newsfragments.