GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-99205: Mark new interpreters and threads as non-static by brandtbucher · Pull Request #99268 · python/cpython

Conversation

@brandtbucher

@brandtbucher brandtbucher commented Nov 9, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: PyThreadState and PyInterpreterState are not freed #99205

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Kludex reacted with thumbs up emoji gpshead reacted with heart emoji
All reactions
  • 👍 1 reaction
  • ❤️ 1 reaction
brandtbucher added 3 commits November 8, 2022 16:31
@brandtbucher
Mark new interpreters and threads as non-static
378210f
@brandtbucher
blurb add
287155b
@brandtbucher
fixup
5171ab1
@brandtbucher brandtbucher added type-bug An unexpected behavior, bug, or error interpreter-core (Objects, Python, Grammar, and Parser dirs) needs backport to 3.11 only security fixes labels Nov 9, 2022
@brandtbucher
brandtbucher requested a review from ericsnowcurrently November 9, 2022 00:39
@brandtbucher brandtbucher self-assigned this Nov 9, 2022
@bedevere-bot bedevere-bot mentioned this pull request Nov 9, 2022
PyThreadState and PyInterpreterState are not freed #99205
Closed
@bedevere-bot bedevere-bot added the awaiting core review label Nov 9, 2022
kumaraditya303
kumaraditya303 approved these changes Nov 9, 2022
View reviewed changes

@kumaraditya303 kumaraditya303 left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ericsnowcurrently
ericsnowcurrently approved these changes Nov 9, 2022
View reviewed changes

@ericsnowcurrently ericsnowcurrently left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I've pointed out two places where a comment would be appropriate. I'm approving the PR under the assumption you'll take care of those.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/pystate.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/pystate.c
memcpy(tstate,
&initial._main_interpreter._initial_thread,
sizeof(*tstate));
tstate->_static = false;

@ericsnowcurrently ericsnowcurrently Nov 9, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a note pointing to PyThreadState_INIT() and indicating that fields set there should be adjusted here as appropriate.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

brandtbucher reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Python/pystate.c
// Set to _PyInterpreterState_INIT.
memcpy(interp, &initial._main_interpreter,
sizeof(*interp));
interp->_static = false;

@ericsnowcurrently ericsnowcurrently Nov 9, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, a note pointing to PyInterpreterState_INIT().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

brandtbucher reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Nov 9, 2022
@ericsnowcurrently

ericsnowcurrently commented Nov 9, 2022

Copy link
Copy Markdown
Member

Thanks for fixing this, BTW.

gpshead reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher
brandtbucher requested a review from pablogsal November 9, 2022 17:16
@brandtbucher

brandtbucher commented Nov 9, 2022

Copy link
Copy Markdown
Member Author

@pablogsal, leak tests didn't catch this because we use the "raw" domain to allocate PyThreadState and PyInterpreterState.

ericsnowcurrently reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fuzzard fuzzard mentioned this pull request Nov 9, 2022
Python3 update to 3.11.0 LibreELEC/LibreELEC.tv#7072
Merged
@pablogsal

pablogsal commented Nov 9, 2022

Copy link
Copy Markdown
Member

Oh interesting, can you confirm that changing the domain to memory makes the test fail?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher

brandtbucher commented Nov 9, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Oh interesting, can you confirm that changing the domain to memory makes the test fail?

You can't. :)

Fatal Python error: _PyMem_DebugCalloc: Python memory allocator called without holding the GIL
Python runtime state: preinitialized

See this comment:

cpython/Python/pystate.c

Lines 818 to 821 in 58ee5d8

// We don't need to allocate a thread state for the main interpreter
// (the common case), but doing it later for the other case revealed a
// reentrancy problem (deadlock). So for now we always allocate before
// taking the interpreters lock. See GH-96071.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher
Feedback from code review
f380af0
@brandtbucher
brandtbucher merged commit 283ab0e into python:main Nov 9, 2022
@miss-islington

miss-islington commented Nov 9, 2022

Copy link
Copy Markdown
Contributor

Thanks @brandtbucher for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting merge label Nov 9, 2022
@bedevere-bot

bedevere-bot commented Nov 9, 2022

Copy link
Copy Markdown

GH-99301 is a backport of this pull request to the 3.11 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 9, 2022
@brandtbucher @miss-islington
pythonGH-99205: Mark new interpreters and threads as non-static (pyth…
27763ef
…onGH-99268)

(cherry picked from commit 283ab0e)

Co-authored-by: Brandt Bucher <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Nov 9, 2022
miss-islington added a commit that referenced this pull request Nov 9, 2022
@miss-islington @brandtbucher
GH-99205: Mark new interpreters and threads as non-static (GH-99268)
7c9c993
(cherry picked from commit 283ab0e)

Co-authored-by: Brandt Bucher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ericsnowcurrently ericsnowcurrently ericsnowcurrently approved these changes
@kumaraditya303 kumaraditya303 kumaraditya303 approved these changes
@pablogsal pablogsal Awaiting requested review from pablogsal

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@brandtbucher brandtbucher

Labels

interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@brandtbucher @ericsnowcurrently @pablogsal @miss-islington @bedevere-bot @kumaraditya303
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.