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-116738: Make mmap module thread-safe by yoney · Pull Request #139237 · python/cpython

Conversation

@yoney

@yoney yoney commented Sep 22, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

These changes make the mmap module thread-safe for FT-Python by protecting the mmap_object against race conditions and undefined behavior. The goal is to provide behavior similar to standard Python builds with the GIL enabled, rather than making mmap fully deterministic or generally recommended for multithreaded use.

cc: @mpage @colesbury @Yhg1s

  • Issue: Audit all built-in modules for thread safety #116738

Sorry, something went wrong.

Uh oh!

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

All reactions
@yoney
pythongh-116738: Make mmap module thread-safe
83c97d7
@bedevere-app bedevere-app Bot mentioned this pull request Sep 22, 2025
Audit all built-in modules for thread safety #116738
Open
@yoney
yoney marked this pull request as ready for review September 22, 2025 15:01
@bedevere-app bedevere-app Bot added the awaiting review label Sep 22, 2025
ZeroIntensity
ZeroIntensity reviewed Sep 22, 2025
View reviewed changes

@ZeroIntensity ZeroIntensity 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 think that it would be helpful in the long run to switch mmap to AC rather than manually adding lock_held functions everywhere.

Sorry, something went wrong.

Uh oh!

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

corona10 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Modules/mmapmodule.c Resolved

Uh oh!

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

@corona10

corona10 commented Sep 23, 2025

Copy link
Copy Markdown
Member

Same question from my side:
Why don t we switch to use AC with '@critical_section'?

All reactions

Sorry, something went wrong.

Uh oh!

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

@yoney

yoney commented Sep 24, 2025

Copy link
Copy Markdown
Contributor Author

Same question from my side: Why don t we switch to use AC with '@critical_section'?

@ZeroIntensity, @corona10: Thank you both for the reviews, I agree that using AC with @critical_section would be a better.

I wanted to ask for your preference: would you like to implement the switch in this PR, or should I hold off on this one and do the implementation separately, then continue with this PR after that? Alternatively, the switch could be done as a follow-up PR.

Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

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

@ZeroIntensity

ZeroIntensity commented Sep 24, 2025

Copy link
Copy Markdown
Member

Let's do AC in this PR.

yoney and corona10 reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

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

yoney added 3 commits October 1, 2025 09:45
@yoney
pythongh-116738: Convert the mmap module to use Argument Clinic
e33497a
@yoney
Merge remote-tracking branch 'upstream/main' into ft_mmap
5c8289d
@yoney
pythongh-116738: Fix Windows build
c80e8ba
kumaraditya303
kumaraditya303 reviewed Oct 2, 2025
View reviewed changes
Comment thread Modules/mmapmodule.c Resolved

Uh oh!

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

@yoney
pythongh-116738: Port all methods to Argument Clinic
e4549fa
@aisk aisk mentioned this pull request Oct 4, 2025
gh-63016: Add flags parameter on mmap.flush #139553
Merged
kumaraditya303
kumaraditya303 reviewed Oct 5, 2025
View reviewed changes
Comment thread Modules/mmapmodule.c Resolved

Uh oh!

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

kumaraditya303
kumaraditya303 reviewed Oct 5, 2025
View reviewed changes
Comment thread Modules/mmapmodule.c Resolved

Uh oh!

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

kumaraditya303
kumaraditya303 reviewed Oct 5, 2025
View reviewed changes
Comment thread Modules/mmapmodule.c Resolved

Uh oh!

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

@kumaraditya303 kumaraditya303 added the topic-free-threading label Oct 5, 2025
yoney added 2 commits October 5, 2025 21:31
@yoney
pythongh-116738: Convert args to AC
01cad24
@yoney
Merge remote-tracking branch 'upstream/main' into ft_mmap
9d6b95d
kumaraditya303
kumaraditya303 approved these changes Oct 6, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Oct 6, 2025
vstinner
vstinner approved these changes Oct 8, 2025
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. I reviewed mmapmodule.c, but I didn't review Lib/test/test_free_threading/test_mmap.py.

Sorry, something went wrong.

Uh oh!

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

All reactions
@kumaraditya303 kumaraditya303 added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 8, 2025
@bedevere-bot

bedevere-bot commented Oct 8, 2025

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @kumaraditya303 for commit 9d6b95d 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F139237%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 8, 2025
kumaraditya303
kumaraditya303 approved these changes Oct 9, 2025
View reviewed changes
@kumaraditya303
kumaraditya303 merged commit 7f155f9 into python:main Oct 9, 2025
68 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label Oct 9, 2025
@kumaraditya303 kumaraditya303 added the needs backport to 3.14 bugs and security fixes label Oct 9, 2025
@miss-islington-app

miss-islington-app Bot commented Oct 9, 2025

Copy link
Copy Markdown

Thanks @yoney for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

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

@miss-islington-app

miss-islington-app Bot commented Oct 9, 2025

Copy link
Copy Markdown

Sorry, @yoney and @kumaraditya303, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 7f155f9c46e2dd7dec5e12ebec3323dfd95fe1f0 3.14
All reactions

Sorry, something went wrong.

Uh oh!

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

@miss-islington-app miss-islington-app Bot assigned kumaraditya303 Oct 9, 2025
kumaraditya303 pushed a commit to kumaraditya303/cpython that referenced this pull request Oct 9, 2025
@yoney @kumaraditya303
[3.14] pythongh-116738: make mmap module thread-safe (pythonGH-139237)
ff5b964
(cherry picked from commit 7f155f9)

Co-authored-by: Alper <[email protected]>
@bedevere-app

bedevere-app Bot commented Oct 9, 2025

Copy link
Copy Markdown

GH-139825 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 9, 2025
@bedevere-bot

bedevere-bot commented Oct 9, 2025

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 FreeBSD Refleaks 3.x (tier-3) has failed when building commit 7f155f9.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1613/builds/2130) and take a look at the build logs.
  4. Check if the failure is related to this commit (7f155f9) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1613/builds/2130

Test leaking resources:

  • test_events: references
  • test_events: memory blocks

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/buildbot/buildarea/3.x.ware-freebsd.refleak/build/Lib/test/support/__init__.py", line 847, in gc_collect
    gc.collect()
    ~~~~~~~~~~^^
ResourceWarning: unclosed <socket.socket fd=9, family=2, type=1, proto=6, laddr=('127.0.0.1', 38818), raddr=('127.0.0.1', 38819)>
Task was destroyed but it is pending!
task: <Task pending name='Task-3140' coro=<BaseSelectorEventLoop._accept_connection2() done, defined at /buildbot/buildarea/3.x.ware-freebsd.refleak/build/Lib/asyncio/selector_events.py:217> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Warning -- Unraisable exception
Exception ignored while calling deallocator <function _SelectorTransport.__del__ at 0x837dda750>:
Traceback (most recent call last):
  File "/buildbot/buildarea/3.x.ware-freebsd.refleak/build/Lib/asyncio/selector_events.py", line 873, in __del__
    _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ResourceWarning: unclosed transport <_SelectorSocketTransport closing fd=9>
k


Traceback (most recent call last):
  File "/buildbot/buildarea/3.x.ware-freebsd.refleak/build/Lib/test/support/__init__.py", line 847, in gc_collect
    gc.collect()
    ~~~~~~~~~~^^
ResourceWarning: unclosed <socket.socket fd=9, family=2, type=1, proto=6, laddr=('127.0.0.1', 55024), raddr=('127.0.0.1', 55025)>
Task was destroyed but it is pending!
task: <Task pending name='Task-1740' coro=<BaseSelectorEventLoop._accept_connection2() done, defined at /buildbot/buildarea/3.x.ware-freebsd.refleak/build/Lib/asyncio/selector_events.py:217> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Warning -- Unraisable exception
Exception ignored while calling deallocator <function _SelectorTransport.__del__ at 0x841981250>:
Traceback (most recent call last):
  File "/buildbot/buildarea/3.x.ware-freebsd.refleak/build/Lib/asyncio/selector_events.py", line 873, in __del__
    _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ResourceWarning: unclosed transport <_SelectorSocketTransport closing fd=9>
k
All reactions

Sorry, something went wrong.

Uh oh!

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

w-hsiung pushed a commit to w-hsiung/cpython that referenced this pull request Oct 9, 2025
@kumaraditya303 @yoney
[3.14] pythongh-116738: make mmap module thread-safe (pythonGH-139237…
926d734
…) (python#139825)

* [3.14] pythongh-116738: make `mmap` module thread-safe (pythonGH-139237)
(cherry picked from commit 7f155f9)

Co-authored-by: Alper <[email protected]>
@yoney
yoney deleted the ft_mmap branch October 19, 2025 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ZeroIntensity ZeroIntensity ZeroIntensity left review comments
@vstinner vstinner vstinner approved these changes
@kumaraditya303 kumaraditya303 kumaraditya303 approved these changes

Uh oh!

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

Assignees

@kumaraditya303 kumaraditya303

Labels

topic-free-threading

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

@yoney @corona10 @ZeroIntensity @bedevere-bot @vstinner @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.