[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light
/ cpython Public
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

bpo-33332: Add signal.valid_signals() #6581

Merged
merged 1 commit into from May 4, 2018

Conversation

Copy link
Member

pitrou commented Apr 23, 2018

pitrou added the type-feature A feature request or enhancement label Apr 23, 2018
pitrou force-pushed the bpo33332-valid-signals branch from ecc75a0 to 94eb990 Compare Apr 23, 2018
Copy link
Member

vstinner left a comment

It would be interesting to also implement the feature on Windows where "valid signals" is hard to guess for a Unix user. See signal_signal() of Modules/signalmodule.c for valid signals: I count 6 signals, 7 if SIGBREAK is also available.

self.assertIsInstance(s, set)
self.assertIn(signal.Signals.SIGINT, s)
self.assertNotIn(0, s)
self.assertNotIn(signal.NSIG, s)
Copy link
Member

vstinner May 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of testing len(s) < NSIG? Maybe len(s) <= NSIG?

Copy link
Member Author

pitrou May 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's very useful.

Copy link
Member

vstinner May 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose is to test if NSIG is consistent with sigfillset(), to check if something is really wrong on a platform. I would like to know if range(0, NSIG) miss some signals on some platforms :-)

Copy link
Member

vstinner commented May 3, 2018

You may also modify:

  • Lib/asyncio/unix_events.py: "if not (1 <= sig < signal.NSIG):" in _check_signal() -- don't forget to patch Lib/test/test_asyncio/test_unix_events.py
  • Lib/test/support/__init__.py: SaveSignals uses "self.signals = list(range(1, signal.NSIG))"

Copy link
Member Author

pitrou commented May 3, 2018

Thanks for the comments. You're right about Windows. I'll also fix asyncio and test.support.

pitrou force-pushed the bpo33332-valid-signals branch from f505b3f to 1b694b3 Compare May 3, 2018
pitrou requested review from 1st1 and asvetlov as code owners May 3, 2018
Copy link
Member

1st1 commented May 3, 2018

Big +1 for this feature. Can you make it return a frozenset though?

Copy link
Member Author

pitrou commented May 3, 2018

Frozen sets are nice if you want to hash them, otherwise I don't really see the point.

pitrou force-pushed the bpo33332-valid-signals branch 2 times, most recently from 6318e94 to 4b52abf Compare May 3, 2018
Copy link
Member

1st1 commented May 3, 2018

Frozen sets are nice if you want to hash them, otherwise I don't really see the point.

What's the point of being able to modify the returned set? ;) If you return a frozenset you can cache it (something that I would recommend doing in this PR anyways).

This isn't a deal breaker, it's just that I would use a frozen set here. Overall LGTM.

pitrou force-pushed the bpo33332-valid-signals branch from 4b52abf to ed4405c Compare May 3, 2018
pitrou force-pushed the bpo33332-valid-signals branch from ed4405c to e7c0fd2 Compare May 3, 2018
Copy link
Member Author

pitrou commented May 3, 2018

Other functions like signal.pthread_sigmask and signal.sigpending return plain sets. So we could return a frozenset from signal.valid_signals but that sounds a bit gratuitous. @vstinner, what do you think?

Copy link
Member

vstinner commented May 3, 2018

First I wanted to get a list, but then I read the PR and I like reusing existing code :-)

If someone wants an immutable type, it's very simple: frozenset(signal.valid_signals()).

An immutable type might be justified if it was a module constant, but it's a function which creates a new object at each call, so IMHO a set is just fine.

I don't want to modify other signal functions just to be pedantic. I like Antoine's rationale to use set in valid_signals().

pitrou merged commit 9d3627e into python:master May 4, 2018
pitrou deleted the bpo33332-valid-signals branch May 4, 2018
yahya-abou-imran pushed a commit to yahya-abou-imran/cpython that referenced this pull request Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants