Skip to content
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

Add a command line flag to suppress default signal handlers #68449

Open
abacabadabacaba mannequin opened this issue May 21, 2015 · 3 comments
Open

Add a command line flag to suppress default signal handlers #68449

abacabadabacaba mannequin opened this issue May 21, 2015 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@abacabadabacaba
Copy link
Mannequin

abacabadabacaba mannequin commented May 21, 2015

BPO 24261
Nosy @bitdancer, @vadmium

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2015-05-21.22:14:39.191>
labels = ['interpreter-core', 'type-feature']
title = 'Add a command line flag to suppress default signal handlers'
updated_at = <Date 2015-05-22.01:25:15.865>
user = 'https://bugs.python.org/abacabadabacaba'

bugs.python.org fields:

activity = <Date 2015-05-22.01:25:15.865>
actor = 'martin.panter'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2015-05-21.22:14:39.191>
creator = 'abacabadabacaba'
dependencies = []
files = []
hgrepos = []
issue_num = 24261
keywords = []
message_count = 3.0
messages = ['243795', '243796', '243798']
nosy_count = 3.0
nosy_names = ['r.david.murray', 'abacabadabacaba', 'martin.panter']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue24261'
versions = []

@abacabadabacaba
Copy link
Mannequin Author

abacabadabacaba mannequin commented May 21, 2015

Currently, Python always changes handling of certain signals on startup: SIGPIPE is ignored, and SIGINT is handled by a function that raises KeyboardInterrupt exception. As a result, if the user presses Ctrl-C, a backtrace is printed to stderr.

Some program may want to change this behavior. For example, they may want to print a user-friendly message, or to terminate without printing anything. They may do that by two means: either by installing their own handler for SIGINT, or by using a try..except block to handle the KeyboardInterrupt exception. However, they both have a flaw: if SIGINT is received during startup, before the program begins execution, the ugly KeyboardInterrupt backtrace is printed nevertheless. So, I propose to add a way to stop Python from installing this default SIGINT handler. I think that the most obvious way is to add a command line switch.

This switch should prevent Python from installing its SIGINT handler. It may also prevent it from ignoring SIGPIPE, so that all signal actions would stay the same as when the program was executed. After that, programs may use signal module to set up their own handlers, if that is desired.

@abacabadabacaba abacabadabacaba mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels May 21, 2015
@bitdancer
Copy link
Member

See also bpo-14228.

@vadmium
Copy link
Member

vadmium commented May 22, 2015

I have often wished for Python to have two modes:

  1. Programming development mode: something like “python -b -Wdefault”, enabling warnings, printing full trackbacks for SIGINT and EPIPE errors, etc. Also possibly catching SystemExit() when raised inside the interactive interpreter.

  2. End-user mode: hide deprecation warnings, no traceback for SIGINT and EPIPE errors (just set an exit status or maybe reraise using the default OS signal handler to set the right exit signal flag to the parent process).

Among other things, this would allow easily switching between reporting KeyboardInterrupt tracebacks (whether triggered at startup or by the main code), and hiding them.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants