Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d3ccde8

Browse files
committed
Issue #7736: Release the GIL around calls to opendir() and closedir()
in the posix module. Patch by Marcin Bachry.
1 parent 327fd40 commit d3ccde8

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ Core and Builtins
9393
Extensions
9494
----------
9595

96+
- Issue #7736: Release the GIL around calls to opendir() and closedir()
97+
in the posix module. Patch by Marcin Bachry.
98+
9699
- Issue #4835: make PyLong_FromSocket_t() and PyLong_AsSocket_t() private
97100
to the socket module, and fix the width of socket descriptors to be
98101
correctly detected under 64-bit Windows.

Modules/posixmodule.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2580,11 +2580,16 @@ posix_listdir(PyObject *self, PyObject *args)
25802580
oname = PyBytes_FromString(".");
25812581
}
25822582
name = PyBytes_AsString(oname);
2583-
if ((dirp = opendir(name)) == NULL) {
2583+
Py_BEGIN_ALLOW_THREADS
2584+
dirp = opendir(name);
2585+
Py_END_ALLOW_THREADS
2586+
if (dirp == NULL) {
25842587
return posix_error_with_allocated_filename(oname);
25852588
}
25862589
if ((d = PyList_New(0)) == NULL) {
2590+
Py_BEGIN_ALLOW_THREADS
25872591
closedir(dirp);
2592+
Py_END_ALLOW_THREADS
25882593
Py_DECREF(oname);
25892594
return NULL;
25902595
}
@@ -2597,7 +2602,9 @@ posix_listdir(PyObject *self, PyObject *args)
25972602
if (errno == 0) {
25982603
break;
25992604
} else {
2605+
Py_BEGIN_ALLOW_THREADS
26002606
closedir(dirp);
2607+
Py_END_ALLOW_THREADS
26012608
Py_DECREF(d);
26022609
return posix_error_with_allocated_filename(oname);
26032610
}
@@ -2621,7 +2628,9 @@ posix_listdir(PyObject *self, PyObject *args)
26212628
}
26222629
Py_DECREF(v);
26232630
}
2631+
Py_BEGIN_ALLOW_THREADS
26242632
closedir(dirp);
2633+
Py_END_ALLOW_THREADS
26252634
Py_DECREF(oname);
26262635

26272636
return d;

0 commit comments

Comments
 (0)