This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author christian.heimes
Recipients christian.heimes, josh.r, manuels
Date 2021-01-31.11:01:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1612090913.78.0.730809903005.issue34321@roundup.psfhosted.org>
In-reply-to
Content
This issue came up in another discussion. I have given it some thought. mmap.mmap() dups the FD because its close() and __exit__() methods close(2) the fd. The size() and resize() methods use the fd to determine the size of the underlying file or to resize the file.

The easiest way to solve the issue while avoind footguns, is an option to not track the fd at all, e.g. "trackfd" with default "True". mmap(..., trackfd=False) would neither dup the fd nor store the fd in its internal struct. In untracked fd case, size() and resize() would no longer work. That's totally fine for mappings without PROT_WRITE.

It's safe to close the fd after mmap call, see https://man7.org/linux/man-pages/man2/mmap.2.html

> After the mmap() call has returned, the file descriptor, fd, can
> be closed immediately without invalidating the mapping.
History
Date User Action Args
2021-01-31 11:01:53christian.heimessetrecipients: + christian.heimes, josh.r, manuels
2021-01-31 11:01:53christian.heimessetmessageid: <1612090913.78.0.730809903005.issue34321@roundup.psfhosted.org>
2021-01-31 11:01:53christian.heimeslinkissue34321 messages
2021-01-31 11:01:53christian.heimescreate