Skip to content

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

Closed

Description

@ericsnowcurrently
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']

    Activity

    1. ericsnowcurrently commented on Jan 11, 2019

      @ericsnowcurrently
      MemberAuthor

      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.

    2. added
      3.8 (EOL)
      interpreter-core
      type-bug
      on Jan 11, 2019
    3. ericsnowcurrently commented on Feb 23, 2019

      @ericsnowcurrently
      MemberAuthor

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

    4. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Labels

    3.8 (EOL)interpreter-coretype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions