Github messages for voidlinux
 help / color / mirror / Atom feed
From: tornaria <tornaria@users.noreply.github.com>
To: ml@inbox.vuxu.org
Subject: Re: python3-prompt_toolkit: don't handle sigint
Date: Sun, 27 Feb 2022 19:19:43 +0100	[thread overview]
Message-ID: <20220227181943.4qm12Y-TCeYK-Ag_JgvwCqH0ppIDCWZwfvVf6wNVG30@z> (raw)
In-Reply-To: <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-35730@inbox.vuxu.org>

[-- Attachment #1: Type: text/plain, Size: 3863 bytes --]

New comment by tornaria on void-packages repository

https://github.com/void-linux/void-packages/pull/35730#issuecomment-1053637263

Comment:
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 `cysignals` here's my take:
 - pure python offers a way to install signal handlers via `signal.signal()`, and so for a pure python program that installs a custom sigint handler, saving and restoring python-level signals is necessary and good enough (no need to use `sigaction`). For example:
```python
$ 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 `prompt_toolkit` that we ship in void, but it works with my patch (even without `cysignals`).
 - when a python program uses `sigaction` to install a custom signal handler, then yes, saving and restoring with `sigaction` is the only way to fix this issue. Unfortunately python doesn't offer any standard way to do that. The only package I know uses `sigaction` to change the sigint handler is `cysignals`. But if `cysignals` is being used to change the sigint handler, then for sure `cysignals` is available to save and restore so we are good!

> Furthermore, if managing signals set with `sigaction` is the right thing to do, it shouldn't be done only if the user chooses to install `cysignals`.


> Thus, either `cysignals` should become a hard requirement of `prompt_toolkit` or it should have its own method to save and restore these signals.

I don't think either is necessary and presumably `cysignals` supports less architectures than `prompt_toolkit` (indeed `sigaction` only makes sense on posix); having its own method requires C code, that would be very simple to copy from `cysignals.pysignals` except `prompt_toolkit` doesn't compile any C code so why make building it more complicated for no good reason).

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.

> 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.

Sure.
 
> I don't want to maintain indefinitely a custom `prompt_toolkit` patch that pulls in `cysignals` to manage these signals. If upstream wants to depend on it, so be it. If they don't care about this problem at all, we'll need another solution.

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.

  parent reply	other threads:[~2022-02-27 18:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-21 14:03 [PR PATCH] " tornaria
2022-02-21 14:11 ` ahesford
2022-02-21 14:11 ` ahesford
2022-02-21 14:35 ` tornaria
2022-02-24 20:59 ` [PR PATCH] [Updated] " tornaria
2022-02-24 21:01 ` tornaria
2022-02-25 15:53 ` ahesford
2022-02-25 21:46 ` tornaria
2022-02-25 22:11 ` ahesford
2022-02-27 18:19 ` tornaria [this message]
2022-02-27 21:48 ` ahesford
2022-02-27 21:49 ` ahesford
2022-02-27 21:49 ` ahesford
2022-02-28  1:35 ` [PR PATCH] [Updated] " tornaria
2022-02-28  1:59 ` tornaria
2022-02-28  2:25 ` [PR PATCH] [Merged]: " ahesford
2022-02-28  2:28 ` ahesford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220227181943.4qm12Y-TCeYK-Ag_JgvwCqH0ppIDCWZwfvVf6wNVG30@z \
    --to=tornaria@users.noreply.github.com \
    --cc=ml@inbox.vuxu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).