Skip to content

gh-155003: Don't try to close mmap in SharedMemory.__del__ - #155070

Merged
gpshead merged 3 commits into
python:mainfrom
takluyver:fix-issue-155003-b
Nov 11, 2026
Merged

gpshead merged 3 commits into
python:mainfrom
takluyver:fix-issue-155003-b

Conversation

@takluyver

@takluyver takluyver commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

This is an alternative to #155007, keeping the file descriptor in the object and fixing the __del__ method to close it without trying to close the mmap or memoryview, which was my original idea in #155003.

I could add, in this PR or separately:

  • The same posix_fallocate() change as in gh-155003: Don't keep file descriptor in multiprocessing SharedMemory object #155007 - but with this option it's orthogonal.
  • A public API to access the fd, probably a .fileno() method, which is a convention for higher level objects which wrap an fd.
  • Use mmap(..., trackfd=False) to skip the duplicate fd within mmap (at a cost of breaking potential workarounds using sm._mmap.resize() & .size())

@takluyver

Copy link
Copy Markdown
Contributor Author

Is there anything else I should be doing on this?

@gpshead gpshead self-assigned this Nov 9, 2026
@gpshead gpshead added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 9, 2026
@gpshead

gpshead commented Nov 9, 2026

Copy link
Copy Markdown
Member

This is likely good. I added a regression test (thank Claude). letting PR CI run and i'll kickoff a buildbot series after that.

@gpshead gpshead added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 9, 2026
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @gpshead for commit 04a3ebb 🤖

Results will be shown at:

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

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

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 9, 2026
@gpshead
gpshead merged commit 4b79d90 into python:main Nov 11, 2026
136 of 141 checks passed
@miss-islington-app

Copy link
Copy Markdown

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

@miss-islington-app

Copy link
Copy Markdown

Sorry, @takluyver and @gpshead, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 4b79d90e935398442d65c59243f8015f062da0f8 3.14

@bedevere-app

bedevere-app Bot commented Nov 11, 2026

Copy link
Copy Markdown

GH-161797 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 11, 2026
@bedevere-app

bedevere-app Bot commented Nov 11, 2026

Copy link
Copy Markdown

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 11, 2026
gpshead added a commit that referenced this pull request Nov 11, 2026
…-155070) (#161797)

gh-155003: Don't try to close mmap in SharedMemory.__del__ (GH-155070)

* Don't try to close mmap in SharedMemory.__del__
* Add a test for SharedMemory finalization with a live buffer, expand NEWS

---------
(cherry picked from commit 4b79d90)

Co-authored-by: Thomas Kluyver <thomas@kluyver.me.uk>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
gpshead added a commit that referenced this pull request Nov 11, 2026
…-155070) (#161798)

* Don't try to close mmap in SharedMemory.__del__
* Add a test for SharedMemory finalization with a live buffer, expand NEWS

---------
(cherry picked from commit 4b79d90)

Co-authored-by: Thomas Kluyver <thomas@kluyver.me.uk>
@takluyver
takluyver deleted the fix-issue-155003-b branch November 11, 2026 08:51
orsenthil pushed a commit to orsenthil/cpython that referenced this pull request Nov 12, 2026
…honGH-155070)

* Don't try to close mmap in SharedMemory.__del__
* Add a test for SharedMemory finalization with a live buffer, expand NEWS

---------

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants