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 — bpo-39984: Move pending calls to PyInterpreterState by vstinner · Pull Request #19066 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Mar 19, 2020 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

If Py_AddPendingCall() is called in a subinterpreter, the function is
now scheduled to be called from the subinterpreter, rather than being
called from the main interpreter.

Each subinterpreter now has its own list of scheduled calls.

  • Move 'pending 'and 'eval_breaker' fields from _PyRuntimeState.ceval
    to PyInterpreterState.ceval.
  • new_interpreter() now calls _PyEval_InitThreads() to initialize
    pending calls (create the lock on pending calls).
  • Fix Py_AddPendingCall() for subinterpreters. It now calls
    _PyThreadState_GET() which works in a subinterpreter if the
    caller holds the GIL, and only falls back on
    PyGILState_GetThisThreadState() if _PyThreadState_GET()
    returns NULL.

https://bugs.python.org/issue39984

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
bpo-39984: Move pending calls to PyInterpreterState
6d7d28e
If Py_AddPendingCall() is called in a subinterpreter, the function is
now scheduled to be called from the subinterpreter, rather than being
called from the main interpreter.

Each subinterpreter now has its own list of scheduled calls.

* Move 'pending 'and 'eval_breaker' fields from _PyRuntimeState.ceval
  to PyInterpreterState.ceval.
* new_interpreter() now calls _PyEval_InitThreads() to initialize
  pending calls (create the lock on pending calls).
* Fix Py_AddPendingCall() for subinterpreters. It now calls
  _PyThreadState_GET() which works in a subinterpreter if the
  caller holds the GIL, and only falls back on
  PyGILState_GetThisThreadState() if _PyThreadState_GET()
  returns NULL.
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Mar 19, 2020
@bedevere-bot bedevere-bot added the awaiting core review label Mar 19, 2020
@vstinner

vstinner commented Mar 19, 2020

Copy link
Copy Markdown
Member Author

If a subinterpreter running in a thread gets a signal, SIGNAL_PENDING_SIGNALS() sets signals_pending to 1 and eval_breaker to 1. In this case, subinterpreter calls handle_signals(), but since it's not the main thread, it does nothing and signals_pending value remains 1.

Later, when the main interpreter will run in the main thread, COMPUTE_EVAL_BREAKER() sets eval_breaker to 1 and so handle_signals() will be called. Finally, signals are handled, and signals_pending is reset to 0.

In short, this PR changes should not break signal handling.

But it's unclear to me what happens with eval_break value when handle_signals() is called in a thread different than the main thread or in a subinterpreter. Will the thread "break" the ceval loop at each instruction to call handle_signals()? Is eval_break value reset to 0? If yes, when?

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner vstinner mentioned this pull request Mar 19, 2020
[WIP] bpo-38865: Py_FinalizeEx() cannot be called in a subinterpreter #19063
Closed
@vstinner

vstinner commented Mar 19, 2020

Copy link
Copy Markdown
Member Author

Signal handling is inefficient in multithreaded applications: I created https://bugs.python.org/issue40010 to propose PR #19067 optimization.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner
vstinner merged commit 50e6e99 into python:master Mar 19, 2020
@bedevere-bot bedevere-bot removed the awaiting core review label Mar 19, 2020
@vstinner
vstinner deleted the subinterp_pending_calls branch March 19, 2020 01:41
@vstinner vstinner mentioned this pull request Mar 19, 2020
bpo-40010: Optimize signal handling in multithreaded applications #19067
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

3 participants

@vstinner @the-knights-who-say-ni @bedevere-bot
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 01402520 — 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.