From ce8e8e85e2d6cd94fc5c23eb4623749a3b8d24be Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Sat, 15 Jun 2019 09:41:05 -0600 Subject: [PATCH] bpo-1572968: Release the GIL while calling mmap() in the mmap module --- .../2019-06-15-09-37-33.bpo-1572968.zftonM.rst | 1 + Modules/mmapmodule.c | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2019-06-15-09-37-33.bpo-1572968.zftonM.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-06-15-09-37-33.bpo-1572968.zftonM.rst b/Misc/NEWS.d/next/Core and Builtins/2019-06-15-09-37-33.bpo-1572968.zftonM.rst new file mode 100644 index 00000000000000..e6c296ca2049dc --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2019-06-15-09-37-33.bpo-1572968.zftonM.rst @@ -0,0 +1 @@ +Release the GIL in :class:`mmap.mmap`. diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 755f1669d8d321..446572b7af6bf1 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -1236,9 +1236,11 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) } } + Py_BEGIN_ALLOW_THREADS m_obj->data = mmap(NULL, map_size, prot, flags, fd, offset); + Py_END_ALLOW_THREADS if (devzero != -1) { close(devzero); @@ -1437,12 +1439,14 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) off_lo = (DWORD)(offset & 0xFFFFFFFF); /* For files, it would be sufficient to pass 0 as size. For anonymous maps, we have to pass the size explicitly. */ + Py_BEGIN_ALLOW_THREADS m_obj->map_handle = CreateFileMapping(m_obj->file_handle, NULL, flProtect, size_hi, size_lo, m_obj->tagname); + Py_END_ALLOW_THREADS if (m_obj->map_handle != NULL) { m_obj->data = (char *) MapViewOfFile(m_obj->map_handle, dwDesiredAccess,