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-37878: Make PyThreadState_DeleteCurrent() Internal by nanjekyejoannah · Pull Request #15315 · python/cpython

Conversation

@nanjekyejoannah

@nanjekyejoannah nanjekyejoannah commented Aug 16, 2019 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Make PyThreadState_DeleteCurrent() Internal.

https://bugs.python.org/issue37878

Sorry, something went wrong.

Uh oh!

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

All reactions
@nanjekyejoannah
Document PyThreadState_DeleteCurrent()
35941ef
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Aug 16, 2019
@bedevere-bot bedevere-bot added docs Documentation in the Doc dir awaiting review labels Aug 16, 2019
@blurb-it
📜🤖 Added by blurb_it.
d27549f
@nanjekyejoannah

nanjekyejoannah commented Aug 16, 2019

Copy link
Copy Markdown
Contributor Author

cc @ericsnowcurrently

All reactions

Sorry, something went wrong.

Uh oh!

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

willingc
willingc reviewed Aug 17, 2019
View reviewed changes

@willingc willingc 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.

Thanks @nanjekyejoannah for the PR. I've made some suggested wording changes for reader clarity.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/c-api/init.rst Resolved

Uh oh!

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

Comment thread Doc/c-api/init.rst Resolved

Uh oh!

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

Comment thread Doc/c-api/init.rst Resolved

Uh oh!

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

nanjekyejoannah and others added 2 commits August 17, 2019 20:07
@nanjekyejoannah @willingc
Update Doc/c-api/init.rst
61ab0c3
Co-Authored-By: Carol Willing <[email protected]>
@nanjekyejoannah @willingc
Update Doc/c-api/init.rst
5034af8
Co-Authored-By: Carol Willing <[email protected]>
@nanjekyejoannah

nanjekyejoannah commented Aug 17, 2019

Copy link
Copy Markdown
Contributor Author

@willingc Changes committed.

willingc 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.

@willingc

willingc commented Aug 17, 2019

Copy link
Copy Markdown
Contributor

Let's give @ericsnowcurrently a chance to review too. Thanks. Please ping me if this is still open later this week and I will merge.

nanjekyejoannah 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.

willingc
willingc previously approved these changes Aug 17, 2019
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Aug 17, 2019
vstinner
vstinner requested changes Aug 19, 2019
View reviewed changes

@vstinner vstinner 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.

I'm not sure that it's a good idea to document this function: https://bugs.python.org/issue37878#msg349954

Sorry, something went wrong.

Uh oh!

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

willingc reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@bedevere-bot bedevere-bot added awaiting changes and removed awaiting merge labels Aug 19, 2019
@bedevere-bot

bedevere-bot commented Aug 19, 2019

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

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

@nanjekyejoannah
make pyThreadState_DeleteCurrent internal
b4d0cce
@nanjekyejoannah
nanjekyejoannah force-pushed the doc_1 branch from 6fd5f7c to b4d0cce Compare August 28, 2019 16:26
@nanjekyejoannah nanjekyejoannah changed the title bpo-37878: Document PyThreadState_DeleteCurrent() bpo-37878: Make PyThreadState_DeleteCurrent() Internal Aug 28, 2019
@nanjekyejoannah
Update 2019-08-16-20-01-10.bpo-37878.MvA6rZ.rst
04677dd
@nanjekyejoannah

nanjekyejoannah commented Aug 28, 2019

Copy link
Copy Markdown
Contributor Author

@vstinner, I made the function internal instead. PTAL

All reactions

Sorry, something went wrong.

Uh oh!

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

vstinner
vstinner requested changes Aug 29, 2019
View reviewed changes
Comment thread Modules/_threadmodule.c Outdated
tstate->interp->num_threads--;
PyThreadState_Clear(tstate);
PyThreadState_DeleteCurrent();
_PyThreadState_DeleteCurrent(&_PyRuntime);

@vstinner vstinner Aug 29, 2019

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 "_PyRuntimeState *runtime = &_PyRuntime;" at the beginning of the function, and replace &_PyRuntime with runtime.

Or maybe even better: add the field to "struct bootstate" and fill the field in thread_PyThread_start_new_thread(). It would make t_bootstrap() more "state-less" (don't access directly global variables).

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
vstinner dismissed willingc’s stale review August 29, 2019 13:02

I dismiss Carol's review since Joannah rewrote her PR, and Carol approved the previous version of the PR.

vstinner
vstinner reviewed Aug 29, 2019
View reviewed changes

@vstinner vstinner 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.

Since it is a public function, even if it's not documented, please document the removal at:
https://docs.python.org/dev/whatsnew/3.9.html#removed

You can mention that the removed function was not documented.

For example, in Python 3.8, I wrote:

"The PyByteArray_Init() and PyByteArray_Fini() functions have been removed. They did nothing since Python 2.7.4 and Python 3.2.0, were excluded from the limited API (stable ABI), and were not documented. (Contributed by Victor Stinner in bpo-35713.)"

Sorry, something went wrong.

Uh oh!

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

All reactions
nanjekyejoannah added 4 commits September 5, 2019 13:26
@nanjekyejoannah
remove state from t_bootstrap()
a38b2b8
@nanjekyejoannah
Remove update
19c7468
@nanjekyejoannah
Merge branch 'master' of https://github.com/python/cpython into doc_1
7972bb4
@nanjekyejoannah
resolve merge conflict
7acf1cb
@nanjekyejoannah

nanjekyejoannah commented Sep 5, 2019

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again .

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-bot bedevere-bot added awaiting change review and removed awaiting changes labels Sep 5, 2019
@bedevere-bot

bedevere-bot commented Sep 5, 2019

Copy link
Copy Markdown

Thanks for making the requested changes!

@vstinner: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

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

vstinner
vstinner approved these changes Sep 5, 2019
View reviewed changes

@vstinner vstinner 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.

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting change review labels Sep 5, 2019
@vstinner
vstinner merged commit 2bc43cd into python:master Sep 5, 2019
@bedevere-bot bedevere-bot removed the awaiting merge label Sep 5, 2019
@vstinner

vstinner commented Sep 5, 2019

Copy link
Copy Markdown
Member

Thanks @nanjekyejoannah! It now looks better: remove the function rather than documenting it :-) I prefer to have a smaller C API!

All reactions

Sorry, something went wrong.

Uh oh!

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

lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
@nanjekyejoannah @willingc @lisroach
bpo-37878: Remove PyThreadState_DeleteCurrent() function (pythonGH-15315
0b1b2d8
)

* Rename PyThreadState_DeleteCurrent()
  to _PyThreadState_DeleteCurrent()
* Move it to the internal C API

Co-Authored-By: Carol Willing <[email protected]>
@tacaswell tacaswell mentioned this pull request Sep 24, 2019
compilation fails with cpython master due to removed function pybind/pybind11#1932
Closed
@tacaswell

tacaswell commented Sep 24, 2019

Copy link
Copy Markdown
Contributor

This breaks pybind 11. Opened an issue with them (pybind/pybind11#1932). Where this should be fixed is a bit over my head at the moment.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Sep 24, 2019

Copy link
Copy Markdown
Member

This breaks pybind 11. Opened an issue with them (pybind/pybind11#1932). Where this should be fixed is a bit over my head at the moment.

Your gil_scoped_acquire class implementation is scary! Would you mind to open a new issue at bugs.python.org to describe your use case and ask to revert the change which removed PyThreadState_DeleteCurrent?

All reactions

Sorry, something went wrong.

Uh oh!

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

@wjakob

wjakob commented Sep 24, 2019

Copy link
Copy Markdown
Contributor

Pybind11 supports some advanced GIL-related tricks that require access this function. For instance, pybind11 can intercept a Python function call on the main() thread and delete the associated thread state, launching a new thread and continuing Python execution there (with a newly created thread state).

Kind of crazy, but why is this useful? UI libraries. On some platforms, it is not legal to poll UI events on any thread other than the main thread. This means that it's impossible to implement a proper UI event loop because Python is hogging the main thread. With the functionality in pybind11's gil_scoped_acquire, I can launch an event polling loop on the main thread, continue running an interactive Python session on another thread, and even swap them back e.g. when the user interface is no longer needed.

All reactions

Sorry, something went wrong.

Uh oh!

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

@wjakob

wjakob commented Sep 24, 2019

Copy link
Copy Markdown
Contributor

@vstinner: I provided some feedback on the Python bugtracker and here.

All reactions

Sorry, something went wrong.

Uh oh!

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

@wjakob

wjakob commented Sep 24, 2019

Copy link
Copy Markdown
Contributor

See https://bugs.python.org/issue38266.

All reactions

Sorry, something went wrong.

Uh oh!

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

DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
@nanjekyejoannah @willingc @DinoV
bpo-37878: Remove PyThreadState_DeleteCurrent() function (pythonGH-15315
2012411
)

* Rename PyThreadState_DeleteCurrent()
  to _PyThreadState_DeleteCurrent()
* Move it to the internal C API

Co-Authored-By: Carol Willing <[email protected]>
@bstaletic bstaletic mentioned this pull request May 22, 2020
Pybind11 doesn't compile with CPython 3.9b1 pybind/pybind11#2224
Closed
@henryiii

henryiii commented May 26, 2020

Copy link
Copy Markdown
Contributor

I'm confused by the attached issue; it looks like the decision was to simply revert the change with the function moved, and not add the underscore; and maybe even make it slightly easier to use. Now that 3.9b1 is out, PyBind11-based libraries cannot build, and the only fix would be to start using a now internal function in CPython. SciPy is an example of a PyBind11-using library.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented May 26, 2020 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

PyThreadState_DeleteCurrent() is declared by the public C API, but it's now excluded from the limited C API. Does pybind11 uses the limited C API? What is your issue? Please comment https://bugs.python.org/issue37878 instead of this merged PR (if you have a bugs.python.org account).

All reactions

Sorry, something went wrong.

Uh oh!

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

@henryiii

henryiii commented May 28, 2020

Copy link
Copy Markdown
Contributor

I'm sorry, I'll add a bugs.python.org account or see if I had one in the past if I need to comment there. I realize, from looking through the code, that an underscore was not added, the function was moved intact (which was not clear from the PR), exactly as it was supposed to be in the issue. The only remaining problem is that the release notes here are wrong: https://docs.python.org/3.9/whatsnew/3.9.html#removed (which is a much better problem).

I'd love it if PyBind11 could use the limited API, but it can't.

Thank you, @vstinner !

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented May 28, 2020

Copy link
Copy Markdown
Member

The only remaining problem is that the release notes here are wrong: https://docs.python.org/3.9/whatsnew/3.9.html#removed (which is a much better problem).

I created #20489 to update the What's New in Python 3.9 document. Would you mind to review my PR?

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner vstinner mentioned this pull request May 28, 2020
bpo-37878: PyThreadState_DeleteCurrent() was not removed #20489
Merged
websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request Jul 20, 2020
@nanjekyejoannah @willingc @websurfer5
bpo-37878: Remove PyThreadState_DeleteCurrent() function (pythonGH-15315
ce63eb9
)

* Rename PyThreadState_DeleteCurrent()
  to _PyThreadState_DeleteCurrent()
* Move it to the internal C API

Co-Authored-By: Carol Willing <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes
@willingc willingc willingc left review comments

Uh oh!

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

Assignees

No one assigned

Labels

docs Documentation in the Doc dir

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.

8 participants

@nanjekyejoannah @willingc @bedevere-bot @vstinner @tacaswell @wjakob @henryiii @the-knights-who-say-ni
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.