Skip to content

Commit 99c470c

Browse files
committed
Release GIL when closing a file descriptor
1 parent 51886da commit 99c470c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,19 @@ protected ArgumentClinicProvider getArgumentClinic() {
523523

524524
@Specialization
525525
PNone close(VirtualFrame frame, int fd,
526-
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
526+
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
527+
@Cached GilNode gil) {
527528
try {
528529
PythonContext ctx = getContext();
529530
if (ctx.getSharedMultiprocessingData().decrementFDRefCount(fd)) {
530531
return PNone.NONE;
531532
}
532-
posixLib.close(getPosixSupport(), fd);
533+
gil.release(true);
534+
try {
535+
posixLib.close(getPosixSupport(), fd);
536+
} finally {
537+
gil.acquire();
538+
}
533539
return PNone.NONE;
534540
} catch (PosixException e) {
535541
throw raiseOSErrorFromPosixException(frame, e);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/PFileIO.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
4444
import com.oracle.graal.python.runtime.AsyncHandler;
45+
import com.oracle.graal.python.runtime.GilNode;
4546
import com.oracle.graal.python.runtime.PosixSupportLibrary;
4647
import com.oracle.graal.python.runtime.PythonContext;
4748
import com.oracle.truffle.api.CompilerDirectives;
@@ -213,9 +214,10 @@ public OwnFD(Object referent, int fd, PythonContext context) {
213214
this.context = context;
214215
}
215216

217+
@SuppressWarnings("try")
216218
protected void doRelease() {
217-
try {
218-
markReleased();
219+
markReleased();
220+
try (GilNode.UncachedRelease gil = GilNode.uncachedRelease()) {
219221
PosixSupportLibrary.getUncached().close(context.getPosixSupport(), (int) getReference());
220222
} catch (PosixSupportLibrary.PosixException e) {
221223
// ignore

0 commit comments

Comments
 (0)