[New-bugs-announce] [issue34321] mmap.mmap() should not necessarily clone the file descriptor

Manuel report at bugs.python.org
Thu Aug 2 09:22:03 EDT 2018

New submission from Manuel <manuel.schoelling at gmx.de>:

mmap.mmap(fileno, length, flags, prot, access, offset) always clones the file descriptor that should be used [1].

The cloning of the file descriptor seems to be done to ensure that the file cannot be closed behind mmap's back, but if you are mmap()'ing a lot of memory regions of a file this can cause a 'Too many open files' error.

I would suggest to add an option to mmap.mmap() that tells it not to clone the file descriptor. This can cause an issue if the file is closed before accessing the mmapped region, so this fact should also be pointed out in the documentation.

[1] https://github.com/python/cpython/blob/master/Modules/mmapmodule.c#L1159

components: Library (Lib)
messages: 322953
nosy: manuels
priority: normal
severity: normal
status: open
title: mmap.mmap() should not necessarily clone the file descriptor
type: enhancement
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list