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

forkserver process should silence KeyboardInterrupt #74371

Closed
pitrou opened this issue Apr 27, 2017 · 11 comments
Closed

forkserver process should silence KeyboardInterrupt #74371

pitrou opened this issue Apr 27, 2017 · 11 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@pitrou
Copy link
Member

pitrou commented Apr 27, 2017

BPO 30185
Nosy @rhettinger, @pitrou, @vstinner, @applio
PRs
  • bpo-30185: avoid KeyboardInterrupt tracebacks in forkserver #1319
  • [3.6] bpo-30185: avoid KeyboardInterrupt tracebacks in forkserver (GH-1319) #1454
  • [3.5] bpo-30185: avoid KeyboardInterrupt tracebacks in forkserver (GH-1319) #1455
  • Files
  • forkserversignal.py
  • 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 = <Date 2017-05-04.15:17:42.999>
    created_at = <Date 2017-04-27.10:51:47.621>
    labels = ['3.7', 'type-bug', 'library']
    title = 'forkserver process should silence KeyboardInterrupt'
    updated_at = <Date 2017-05-04.16:19:48.010>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2017-05-04.16:19:48.010>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-05-04.15:17:42.999>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2017-04-27.10:51:47.621>
    creator = 'pitrou'
    dependencies = []
    files = ['46832']
    hgrepos = []
    issue_num = 30185
    keywords = []
    message_count = 11.0
    messages = ['292420', '292421', '292422', '292425', '292426', '292983', '292986', '292989', '292996', '292997', '292998']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'pitrou', 'vstinner', 'sbt', 'davin']
    pr_nums = ['1319', '1454', '1455']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue30185'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @pitrou
    Copy link
    Member Author

    pitrou commented Apr 27, 2017

    The forkserver intermediate process is an implementation detail. However, if you Ctrl-C the main process, the forkserver process will exit with a KeyboardInterrupt traceback, even if the main process catches KeyboardInterrupt to exit silently. This produces stderr such as:

    $ ./python forkserversignal.py 
    ^CTraceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/antoine/cpython/default/Lib/multiprocessing/forkserver.py", line 164, in main
        rfds = [key.fileobj for (key, events) in selector.select()]
      File "/home/antoine/cpython/default/Lib/selectors.py", line 445, in select
        fd_event_list = self._epoll.poll(timeout, max_ev)
    KeyboardInterrupt

    For the sake of usability, forkserver should probably silence those tracebacks by default, for example by changing the default signal handler in the forkserver process (but children forked by the forkserver process should probably get the default Python signal handlers...).

    Not sure this can be considered a bugfix or an enhancement.

    @pitrou pitrou added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 27, 2017
    @pitrou
    Copy link
    Member Author

    pitrou commented Apr 27, 2017

    Uploading small reproducer script.

    @pitrou
    Copy link
    Member Author

    pitrou commented Apr 27, 2017

    A simpler solution would actually be to catch KeyboardInterrupt inside the forkserver loop and exit cleanly...

    @vstinner
    Copy link
    Member

    A simpler solution would actually be to catch KeyboardInterrupt inside the forkserver loop and exit cleanly...

    I'm not sure that we always want to exit on CTRL-c. But I agree that the forkserver has to handle CTRL-c. Maybe ignore it, but be killed when its master gets a CTRL-c?

    @pitrou
    Copy link
    Member Author

    pitrou commented Apr 27, 2017

    I'm not sure that we always want to exit on CTRL-c.

    That's what the forkserver does right now, it's just that it does it with a traceback that's useless to the user.

    Maybe ignore it, but be killed when its master gets a CTRL-c?

    That's a possibility (the forkserver should already exit automatically when its parent dies), the problem is what to do for the forkserver's children? Should they restore the default signal handler?

    Simply silencing the KeyboardInterrupt traceback at least is a straightforward solution with little risk of side effects.

    @pitrou
    Copy link
    Member Author

    pitrou commented May 4, 2017

    New changeset 6dd4d73 by Antoine Pitrou in branch 'master':
    bpo-30185: avoid KeyboardInterrupt tracebacks in forkserver (bpo-1319)
    6dd4d73

    @pitrou
    Copy link
    Member Author

    pitrou commented May 4, 2017

    New changeset a7e48b5 by Antoine Pitrou in branch '3.6':
    [3.6] bpo-30185: avoid KeyboardInterrupt tracebacks in forkserver (GH-1319) (bpo-1454)
    a7e48b5

    @pitrou
    Copy link
    Member Author

    pitrou commented May 4, 2017

    New changeset 7299088 by Antoine Pitrou in branch '3.5':
    [3.5] bpo-30185: avoid KeyboardInterrupt tracebacks in forkserver (GH-1319) (bpo-1455)
    7299088

    @pitrou pitrou closed this as completed May 4, 2017
    @vstinner
    Copy link
    Member

    vstinner commented May 4, 2017

    Python 2.7 isn't affected by this bug?

    @pitrou
    Copy link
    Member Author

    pitrou commented May 4, 2017

    There is no forkserver in 2.7.

    @vstinner
    Copy link
    Member

    vstinner commented May 4, 2017

    There is no forkserver in 2.7.

    Oh right, it's specific to forkserver, ok ;-) Thank you for the fix.

    @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
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants