-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
python3-prompt_toolkit: don't handle sigint #35730
Conversation
We at least need to wait until upstream comments on your proposed fix before adopting it here. Presumably they merged the change for a reason. |
I understand, you can see their reasons here: prompt-toolkit/python-prompt-toolkit#1537 However let me stress that this breaks sagemath very badly. If I'm in the middle of a computation session and I happen to run a command that takes a very long time, then Ctrl-C is broken and I can't get back to my session (I can Ctrl-Z and kill but then I will loose the session -- a non-obvious workaround is to send SIGALRM instead of SIGTERM which allows to recover). The alternative to this patch is to revert prompt_toolkit to 3.0.24 until upstream says something. Is there anything requiring a more recent version of prompt_toolkit? |
3de3ead
to
7de146d
Compare
@ahesford a different approach, explained here: prompt-toolkit/python-prompt-toolkit#1576 (comment). What do you think? |
Between the two options, I suppose I favor just disabling the SIGINT handler by default. Adding What I would like to see from upstream are some guidance about the following questions:
If upstream doesn't respond soon, we can pick up the original patch in this PR. |
My last patch is not adding This is a generic fix that would work for any program that sets the sigint handler, either just the python sigint handler or the whole os-level sigint handler..
I don't think so. The way The way Now The question is: how to save and restore the sigint handler? Python stdlib offers How to save and restore the os-level signal handler? Using
I later convinced myself that this is not a good solution. In fact, ipython itself also crashes when receiving a
No, because ipython itself knows nothing at all about
I don't think there's any way to fix the signal-handling logic of
As I explained above, I think the second patch is better. |
I misunderstood when The " We really need some guidance from upstream about whether they intend to care about this problem at all and, if so, how they intend to solve it. I don't want to maintain indefinitely a custom |
I agree that we should wait for comments for upstream, although meanwhile sagemath is broken in a very annoying way. About your comment on the optional use of
$ ipython
Python 3.10.2 (main, Jan 15 2022, 03:11:32) [GCC 10.2.1 20201203]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.0.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: def h(x,y): print("Our custom handler received a sigint", x, y); raise KeyboardInterrupt
In [2]: import signal
In [3]: signal.signal(signal.SIGINT, h)
Out[3]: <cyfunction python_check_interrupt at 0x7f12316bcba0>
In [4]: while True: pass
^COur custom handler received a sigint 2 <frame at 0x55c760ab21c0, file '<ipython-input-4-b16dc615ea65>', line 1, code <module>>
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
Input In [4], in <module>
----> 1 while True: pass
Input In [1], in h(x, y)
----> 1 def h(x,y): print("Our custom handler received a sigint", x, y); raise KeyboardInterrupt
KeyboardInterrupt:
In [5]: The above snippet is broken with the version of
I don't think either is necessary and presumably In case another program or python package installs a custom sigint handler and suffers of this issue, we can figure out how to fix it (for instance, we make that package depend on python3-cysignals). Right now there aren't many packages in void that use prompt_toolkit. In any case, if they break because of this they are already broken, my fix won't make them more broken but possibly less broken.
Sure.
I can help to maintain the patch, at least for the time being while the issue is (hopefully) resolved upstream, and I can help to figure out another solution if this one doesn't work in the end. |
I understand the isssue and how your patch fixes it. Unless upstream merges your proposed handler changes, I will not accept a Void patch that does the same. The two options I will accept before upstream makes a decision are:
Option 1 may cause IPython to crash when it receives SIGINT, but that is functionally no worse than a revert to a prior version of Whether The optional dependency on Upstream needs to decide whether they even care about this problem and, if so, how to solve it. They might
If you do PR your optional approach upstream, you should probably define a package option to declare the dependency so that the package can advertise the possibility. |
7de146d
to
ccb29d4
Compare
Let's do this, I've force-pushed my original patch. This is completely acceptable for sagemath.
I can live with this too. I hadn't even noticed this before I looked at the xonsh bug report.
Just for the record, assuming I understand the way python imports work, my patch doesn't add branches in the event loop. It tries to import cysignals.pysignals ONCE when prompt_toolkit is imported for the first time. If that fails, it will import instead alternative pure python functions (not using cysignals / not preserving the os-level sigint handler). These functions are unconditionally called once when prompt starts (to save the sigint handler) and once when the prompt finishes (to restore the sigint handler). The event loop runs all the prompt editing, completion, etc, etc, but this will not mess with signals at all.
I'll wait for comments first before doing a PR. I might ask you for help then, since my understanding of python packaging and hard vs optional dependencies is almost nil. |
Thanks for entertaining my debate. If you think that I can provide assistance, feel free to tag me in a PR or ping me on IRC. |
Fixes #35712
See also: prompt-toolkit/python-prompt-toolkit#1576
Testing the changes