bpo-45012: Release GIL around stat in os.scandir (GH-28085)

Releasing GIL allows other threads to continue
its work when os.scandir is fetching DirEntry.stat
info from file system.
This commit is contained in:
Stanisław Skonieczny 2021-09-07 19:55:20 +02:00 committed by GitHub
parent 750368cbcd
commit 9dc363ee7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View file

@ -1645,6 +1645,7 @@ J. Sipprell
Ngalim Siregar Ngalim Siregar
Kragen Sitaker Kragen Sitaker
Kaartic Sivaraam Kaartic Sivaraam
Stanisław Skonieczny
Roman Skurikhin Roman Skurikhin
Ville Skyttä Ville Skyttä
Michael Sloan Michael Sloan

View file

@ -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.

View file

@ -13489,8 +13489,10 @@ _Py_COMP_DIAG_POP
if (self->dir_fd != DEFAULT_DIR_FD) { if (self->dir_fd != DEFAULT_DIR_FD) {
#ifdef HAVE_FSTATAT #ifdef HAVE_FSTATAT
if (HAVE_FSTATAT_RUNTIME) { if (HAVE_FSTATAT_RUNTIME) {
Py_BEGIN_ALLOW_THREADS
result = fstatat(self->dir_fd, path, &st, result = fstatat(self->dir_fd, path, &st,
follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW); follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW);
Py_END_ALLOW_THREADS
} else } else
#endif /* HAVE_FSTATAT */ #endif /* HAVE_FSTATAT */
@ -13503,11 +13505,15 @@ _Py_COMP_DIAG_POP
else else
#endif #endif
{ {
if (follow_symlinks) Py_BEGIN_ALLOW_THREADS
if (follow_symlinks) {
result = STAT(path, &st); result = STAT(path, &st);
else }
else {
result = LSTAT(path, &st); result = LSTAT(path, &st);
} }
Py_END_ALLOW_THREADS
}
#if defined(MS_WINDOWS) && !USE_UNICODE_WCHAR_CACHE #if defined(MS_WINDOWS) && !USE_UNICODE_WCHAR_CACHE
PyMem_Free(path); PyMem_Free(path);
#else /* USE_UNICODE_WCHAR_CACHE */ #else /* USE_UNICODE_WCHAR_CACHE */