]> granicus.if.org Git - python/commitdiff
Bug #1432525: os.listdir now releases the GIL while calling
authorGeorg Brandl <georg@python.org>
Tue, 7 Mar 2006 12:48:03 +0000 (12:48 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 7 Mar 2006 12:48:03 +0000 (12:48 +0000)
readdir().

Modules/posixmodule.c

index ba1e6c0ad577b3f8ad0c8e96b93b27dc521052b5..3c28424fd3d01aee9874ae9fec28201ba0eb1f07 100644 (file)
@@ -1640,6 +1640,7 @@ posix_listdir(PyObject *self, PyObject *args)
 
        PyObject *d, *v;
        HANDLE hFindFile;
+       BOOL result;
        WIN32_FIND_DATA FileData;
        /* MAX_PATH characters could mean a bigger encoded string */
        char namebuf[MAX_PATH*2+5];
@@ -1692,7 +1693,10 @@ posix_listdir(PyObject *self, PyObject *args)
                                        break;
                                }
                                Py_DECREF(v);
-                       } while (FindNextFileW(hFindFile, &wFileData) == TRUE);
+                               Py_BEGIN_ALLOW_THREADS
+                               result = FindNextFileW(hFindFile, &wFileData);
+                               Py_END_ALLOW_THREADS
+                       } while (result == TRUE);
 
                        if (FindClose(hFindFile) == FALSE) {
                                Py_DECREF(d);
@@ -1746,7 +1750,10 @@ posix_listdir(PyObject *self, PyObject *args)
                        break;
                }
                Py_DECREF(v);
-       } while (FindNextFile(hFindFile, &FileData) == TRUE);
+               Py_BEGIN_ALLOW_THREADS
+               result = FindNextFile(hFindFile, &FileData);
+               Py_END_ALLOW_THREADS
+       } while (result == TRUE);
 
        if (FindClose(hFindFile) == FALSE) {
                Py_DECREF(d);
@@ -1848,7 +1855,12 @@ posix_listdir(PyObject *self, PyObject *args)
                PyMem_Free(name);
                return NULL;
        }
-       while ((ep = readdir(dirp)) != NULL) {
+       for (;;) {
+               Py_BEGIN_ALLOW_THREADS
+               ep = readdir(dirp);
+               Py_END_ALLOW_THREADS
+               if (ep == NULL)
+                       break;
                if (ep->d_name[0] == '.' &&
                    (NAMLEN(ep) == 1 ||
                     (ep->d_name[1] == '.' && NAMLEN(ep) == 2)))