Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-134745: Change PyThread_allocate_lock() implementation to PyMutex#134747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
vstinner wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
fromvstinner:pymutex

Conversation

vstinner
Copy link
Member

@vstinnervstinner commentedMay 26, 2025
edited by bedevere-appbot
Loading

PyMutex is a fast and portable lock currently only used internally by Python. This change modify _thread.allocate_lock() and threading.Lock to reuse PyMutex.

@vstinner
Copy link
MemberAuthor

This draft PR currently only modifyPython/thread_pthread.h. I leftPython/thread_nt.h unchanged.

_PyThread_at_fork_reinit() is still implemented by allocating a new lock and leaking the old lock.

@vstinner
Copy link
MemberAuthor

@colesbury: What do you think of this idea? Does it make sense? Do you see any possible issue?

If the approach makes sense, I will update my PR to modify also the Windows implementation.

YvesDup reacted with thumbs up emoji

@colesbury
Copy link
Contributor

I think the idea is fine, but the PR title and description are confusing.threading.Lock /_thread.lock /_thread._thread.allocate_lock() already usePyMutex (all three are the same thing):

typedefstruct {
PyObject_HEAD
PyMutexlock;
}lockobject;

This PR changes the implementation of the C APIPyThread_allocate_lock(). We are generally usingPyMutex directly instead ofPyThread_allocate_lock() in new code, and we've also changed a lot of existing uses too. UsingPyMutex directly is simpler because it avoids an allocation that may fail.

I think it's okay to change the implementation ofPyThread_allocate_lock(). It looks like it's going to simplify the code, but there's some risk of unknown behavioral changes.

@vstinnervstinner changed the titlegh-134745: Change threading.Lock implementation to PyMutexgh-134745: Change PyThread_allocate_lock() implementation to PyMutexMay 27, 2025
Don't call signal handlers if interrupted, only return PY_LOCK_INTR.
@vstinnervstinner marked this pull request as ready for reviewMay 28, 2025 10:54
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@colesburycolesburycolesbury left review comments

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@vstinner@colesbury

[8]ページ先頭

©2009-2025 Movatter.jp