Christian Heimes <li...@cheimes.de> added the comment:
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. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34321> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com