]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45012: Release GIL around stat in os.scandir (GH-28085)
authorStanisław Skonieczny <stanislaw.skonieczny@gmail.com>
Tue, 7 Sep 2021 17:55:20 +0000 (19:55 +0200)
committerGitHub <noreply@github.com>
Tue, 7 Sep 2021 17:55:20 +0000 (19:55 +0200)
Releasing GIL allows other threads to continue
its work when os.scandir is fetching DirEntry.stat
info from file system.

Misc/ACKS
Misc/NEWS.d/next/Core and Builtins/2021-08-31-11-09-52.bpo-45012.ueeOcx.rst [new file with mode: 0644]
Modules/posixmodule.c

index 481e46d4c173200e54c57a42000b9b24c7a0244a..23c92abb4d02a73552c512e15cecc428dcd6d09a 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1645,6 +1645,7 @@ J. Sipprell
 Ngalim Siregar
 Kragen Sitaker
 Kaartic Sivaraam
+Stanisław Skonieczny
 Roman Skurikhin
 Ville Skyttä
 Michael Sloan
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-08-31-11-09-52.bpo-45012.ueeOcx.rst b/Misc/NEWS.d/next/Core and Builtins/2021-08-31-11-09-52.bpo-45012.ueeOcx.rst
new file mode 100644 (file)
index 0000000..91cb3a9
--- /dev/null
@@ -0,0 +1,2 @@
+In :mod:`posix`, release GIL during ``stat()``, ``lstat()``, and
+``fstatat()`` syscalls made by :func:`os.DirEntry.stat`. Patch by Stanisław Skonieczny.
index 73e7e60fe63ff45b79e27b1d2d9890d81f435429..89659ae3490dadd91b22670d52e0255b558ee0d0 100644 (file)
@@ -13489,8 +13489,10 @@ _Py_COMP_DIAG_POP
     if (self->dir_fd != DEFAULT_DIR_FD) {
 #ifdef HAVE_FSTATAT
       if (HAVE_FSTATAT_RUNTIME) {
+        Py_BEGIN_ALLOW_THREADS
         result = fstatat(self->dir_fd, path, &st,
                          follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW);
+        Py_END_ALLOW_THREADS
       } else
 
 #endif /* HAVE_FSTATAT */
@@ -13503,10 +13505,14 @@ _Py_COMP_DIAG_POP
     else
 #endif
     {
-        if (follow_symlinks)
+        Py_BEGIN_ALLOW_THREADS
+        if (follow_symlinks) {
             result = STAT(path, &st);
-        else
+        }
+        else {
             result = LSTAT(path, &st);
+        }
+        Py_END_ALLOW_THREADS
     }
 #if defined(MS_WINDOWS) && !USE_UNICODE_WCHAR_CACHE
     PyMem_Free(path);