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

Check for main interpreter when checking for "main" thread (for signal handling) #79905

Closed
ericsnowcurrently opened this issue Jan 11, 2019 · 2 comments
Assignees
Labels
3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@ericsnowcurrently
Copy link
Member

BPO 35724
Nosy @ericsnowcurrently
PRs
  • bpo-35724: Explicitly require the main interpreter for signal-handling. #11530
  • 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 = 'https://github.com/ericsnowcurrently'
    closed_at = <Date 2019-02-23.22:41:49.385>
    created_at = <Date 2019-01-11.21:04:47.065>
    labels = ['interpreter-core', 'type-bug', '3.8']
    title = 'Check for main interpreter when checking for "main" thread (for signal handling)'
    updated_at = <Date 2019-02-23.22:41:49.385>
    user = 'https://github.com/ericsnowcurrently'

    bugs.python.org fields:

    activity = <Date 2019-02-23.22:41:49.385>
    actor = 'eric.snow'
    assignee = 'eric.snow'
    closed = True
    closed_date = <Date 2019-02-23.22:41:49.385>
    closer = 'eric.snow'
    components = ['Interpreter Core']
    creation = <Date 2019-01-11.21:04:47.065>
    creator = 'eric.snow'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35724
    keywords = ['patch', 'patch']
    message_count = 2.0
    messages = ['333506', '336411']
    nosy_count = 1.0
    nosy_names = ['eric.snow']
    pr_nums = ['11530']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue35724'
    versions = ['Python 3.8']

    @ericsnowcurrently
    Copy link
    Member Author

    The code in Modules/signalsmodule.c (as well as a few other places in the code) has a concept of a "main" thread. It's the OS thread where Py_Initialize() was called (and likely the process's original thread). For various good reasons, we ensure that signal handling happens relative to that ("main") thread.

    The problem is that we track the OS thread (by ID), which multiple interpreters can share. What we really want is to track the original PyThreadState. Otherwise signal-handling could happen (or handlers get added) in the wrong interpreter.

    Options:

    1. track the PyThreadState pointer instead of the OS thread ID
    2. check that the current interpreter is the main one, in every place we check for the main thread

    From what I can tell, the simpler option is #2.

    @ericsnowcurrently ericsnowcurrently added 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jan 11, 2019
    @ericsnowcurrently
    Copy link
    Member Author

    New changeset 64d6cc8 by Eric Snow in branch 'master':
    bpo-35724: Explicitly require the main interpreter for signal-handling. (GH-11530)
    64d6cc8

    @ericsnowcurrently ericsnowcurrently self-assigned this Feb 23, 2019
    @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.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant