This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Check for main interpreter when checking for "main" thread (for signal handling)
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.snow Nosy List: eric.snow
Priority: normal Keywords: patch, patch

Created on 2019-01-11 21:04 by eric.snow, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11530 merged eric.snow, 2019-01-11 21:49
Messages (2)
msg333506 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2019-01-11 21:04
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.
msg336411 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2019-02-23 22:40
New changeset 64d6cc826dacebc2493b1bb5e8cb97828eb76f81 by Eric Snow in branch 'master':
bpo-35724: Explicitly require the main interpreter for signal-handling. (GH-11530)
https://github.com/python/cpython/commit/64d6cc826dacebc2493b1bb5e8cb97828eb76f81
History
Date User Action Args
2022-04-11 14:59:10adminsetgithub: 79905
2019-02-23 22:41:49eric.snowsetkeywords: patch, patch
assignee: eric.snow
status: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-02-23 22:40:49eric.snowsetmessages: + msg336411
2019-02-23 19:39:56eric.snowsetpull_requests: - pull_request11124
2019-01-11 21:49:21eric.snowsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request11124
2019-01-11 21:49:19eric.snowsetkeywords: + patch
stage: needs patch -> needs patch
pull_requests: + pull_request11123
2019-01-11 21:04:47eric.snowcreate