@@ -222,14 +222,20 @@ private static void errorCleanup(VirtualFrame frame, PFileIO self, boolean fdIsO
222
222
private int open (VirtualFrame frame , String name , int flags , int mode ,
223
223
PythonContext ctxt ,
224
224
PosixSupportLibrary posixLib ,
225
+ GilNode gil ,
225
226
BranchProfile errorProfile ) {
226
227
Object path = posixLib .createPathFromString (ctxt .getPosixSupport (), name );
227
228
if (path == null ) {
228
229
throw raise (ValueError , EMBEDDED_NULL_BYTE );
229
230
}
230
231
while (true ) {
231
232
try {
232
- return posixLib .openat (ctxt .getPosixSupport (), AT_FDCWD .value , path , flags , mode );
233
+ gil .release (true );
234
+ try {
235
+ return posixLib .openat (ctxt .getPosixSupport (), AT_FDCWD .value , path , flags , mode );
236
+ } finally {
237
+ gil .acquire ();
238
+ }
233
239
} catch (PosixException e ) {
234
240
errorProfile .enter ();
235
241
if (e .getErrorCode () == OSErrorEnum .EINTR .getNumber ()) {
@@ -303,7 +309,8 @@ void doInit(VirtualFrame frame, PFileIO self, Object nameobj, IONodes.IOMode mod
303
309
@ Cached SetAttributeNode .Dynamic setAttr ,
304
310
@ Cached SysModuleBuiltins .AuditNode auditNode ,
305
311
@ Cached BranchProfile exceptionProfile ,
306
- @ Cached ConditionProfile errorProfile ) {
312
+ @ Cached ConditionProfile errorProfile ,
313
+ @ Cached GilNode gil ) {
307
314
if (self .getFD () >= 0 ) {
308
315
if (self .isCloseFD ()) {
309
316
/* Have to close the existing file first. */
@@ -337,7 +344,7 @@ void doInit(VirtualFrame frame, PFileIO self, Object nameobj, IONodes.IOMode mod
337
344
}
338
345
339
346
if (opener instanceof PNone ) {
340
- self .setFD (open (frame , name , flags , 0666 , ctxt , posixLib , exceptionProfile ), ctxt );
347
+ self .setFD (open (frame , name , flags , 0666 , ctxt , posixLib , gil , exceptionProfile ), ctxt );
341
348
} else {
342
349
Object fdobj = callOpener .execute (frame , opener , nameobj , flags );
343
350
if (!indexCheckNode .execute (fdobj )) {
@@ -363,7 +370,13 @@ void doInit(VirtualFrame frame, PFileIO self, Object nameobj, IONodes.IOMode mod
363
370
}
364
371
self .setBlksize (DEFAULT_BUFFER_SIZE );
365
372
try {
366
- long [] fstatResult = posixLib .fstat (ctxt .getPosixSupport (), self .getFD ());
373
+ long [] fstatResult ;
374
+ gil .release (true );
375
+ try {
376
+ fstatResult = posixLib .fstat (ctxt .getPosixSupport (), self .getFD ());
377
+ } finally {
378
+ gil .acquire ();
379
+ }
367
380
/*
368
381
* On Unix, open will succeed for directories. In Python, there should be no
369
382
* file objects referring to directories, so we need a check.
@@ -396,8 +409,13 @@ void doInit(VirtualFrame frame, PFileIO self, Object nameobj, IONodes.IOMode mod
396
409
* it might be done only on the first write()).
397
410
*/
398
411
try {
399
- long res = posixLib .lseek (ctxt .getPosixSupport (), self .getFD (), 0 , mapPythonSeekWhenceToPosix (SEEK_END ));
400
- self .setSeekable (res >= 0 ? 1 : 0 );
412
+ gil .release (true );
413
+ try {
414
+ long res = posixLib .lseek (ctxt .getPosixSupport (), self .getFD (), 0 , mapPythonSeekWhenceToPosix (SEEK_END ));
415
+ self .setSeekable (res >= 0 ? 1 : 0 );
416
+ } finally {
417
+ gil .acquire ();
418
+ }
401
419
} catch (PosixException e ) {
402
420
exceptionProfile .enter ();
403
421
if (self .getSeekable () < 0 ) {
@@ -744,9 +762,15 @@ protected ArgumentClinicProvider getArgumentClinic() {
744
762
@ Specialization (guards = "!self.isClosed()" )
745
763
Object seek (VirtualFrame frame , PFileIO self , long pos , int whence ,
746
764
@ CachedLibrary ("getPosixSupport()" ) PosixSupportLibrary posixLib ,
765
+ @ Cached GilNode gil ,
747
766
@ Cached BranchProfile exceptionProfile ) {
748
767
try {
749
- return internalSeek (self , pos , whence , getPosixSupport (), posixLib );
768
+ gil .release (true );
769
+ try {
770
+ return internalSeek (self , pos , whence , getPosixSupport (), posixLib );
771
+ } finally {
772
+ gil .acquire ();
773
+ }
750
774
} catch (PosixException e ) {
751
775
exceptionProfile .enter ();
752
776
throw raiseOSErrorFromPosixException (frame , e );
@@ -985,8 +1009,14 @@ Object closedError(@SuppressWarnings("unused") PFileIO self) {
985
1009
abstract static class IsattyNode extends PythonUnaryBuiltinNode {
986
1010
@ Specialization (guards = "!self.isClosed()" )
987
1011
boolean isatty (@ SuppressWarnings ("unused" ) PFileIO self ,
988
- @ CachedLibrary ("getPosixSupport()" ) PosixSupportLibrary posixLib ) {
989
- return posixLib .isatty (getPosixSupport (), self .getFD ());
1012
+ @ CachedLibrary ("getPosixSupport()" ) PosixSupportLibrary posixLib ,
1013
+ @ Cached GilNode gil ) {
1014
+ gil .release (true );
1015
+ try {
1016
+ return posixLib .isatty (getPosixSupport (), self .getFD ());
1017
+ } finally {
1018
+ gil .acquire ();
1019
+ }
990
1020
}
991
1021
992
1022
@ Specialization (guards = "self.isClosed()" )
0 commit comments