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

Merged
vstinner merged 7 commits intopython:mainfromvstinner:pymutex
May 30, 2025

Conversation

vstinner
Copy link
Member

@vstinnervstinner commentedMay 26, 2025
edited by colesbury
Loading

PyMutex is a fast and portable lock currently only used internally by Python. This change modifiesPyThread_allocate_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.
Copy link
Contributor

@colesburycolesbury left a comment

Choose a reason for hiding this comment

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

This LGTM, but I think you should include a NEWS entry. One behavioral change is that previouslyintr_flag was ignored on Windows, but now it actually makes the acquisitions interruptible.

vstinnerand others added2 commitsMay 30, 2025 11:29
Co-authored-by: Sam Gross <colesbury@gmail.com>
@vstinnervstinnerenabled auto-merge (squash)May 30, 2025 09:42
@vstinnervstinnerdisabled auto-mergeMay 30, 2025 09:44
@vstinnervstinnerenabled auto-merge (squash)May 30, 2025 09:45
@vstinnervstinner merged commitebf6d13 intopython:mainMay 30, 2025
39 checks passed
@vstinnervstinner deleted the pymutex branchMay 30, 2025 10:15
@vstinner
Copy link
MemberAuthor

Merged, thanks for the review@colesbury.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@colesburycolesburycolesbury approved these changes

Assignees
No one assigned
Labels
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