@@ -410,8 +410,8 @@ private void execv(VirtualFrame frame, PosixPath path, Object argv, SequenceStor
410
410
411
411
auditNode .audit ("os.exec" , path .originalObject , argv , PNone .NONE );
412
412
413
+ gil .release (true );
413
414
try {
414
- gil .release (true );
415
415
posixLib .execv (getPosixSupport (), path .value , opaqueArgs );
416
416
} catch (PosixException e ) {
417
417
gil .acquire ();
@@ -498,11 +498,10 @@ int open(VirtualFrame frame, PosixPath path, int flags, int mode, int dirFd,
498
498
return posixLib .openat (getPosixSupport (), dirFd , path .value , fixedFlags , mode );
499
499
} catch (PosixException e ) {
500
500
errorProfile .enter ();
501
- gil .acquire ();
502
501
if (e .getErrorCode () == OSErrorEnum .EINTR .getNumber ()) {
503
502
PythonContext .triggerAsyncActions (this );
504
- gil .release (true );
505
503
} else {
504
+ gil .acquire (); // need GIL to construct OSError
506
505
throw raiseOSErrorFromPosixException (frame , e , path .originalObject );
507
506
}
508
507
}
@@ -580,9 +579,7 @@ public PBytes read(VirtualFrame frame, int fd, int length,
580
579
} catch (PosixException e ) {
581
580
errorProfile .enter ();
582
581
if (e .getErrorCode () == OSErrorEnum .EINTR .getNumber ()) {
583
- gil .acquire (); // need gil to trigger actions or construct OSError
584
582
PythonContext .triggerAsyncActions (this );
585
- gil .release (true ); // continue read loop without gil
586
583
} else {
587
584
throw e ;
588
585
}
@@ -629,9 +626,7 @@ public long write(int fd, byte[] data,
629
626
} catch (PosixException e ) {
630
627
errorProfile .enter ();
631
628
if (e .getErrorCode () == OSErrorEnum .EINTR .getNumber ()) {
632
- gil .acquire ();
633
629
PythonContext .triggerAsyncActions (this );
634
- gil .release (true );
635
630
} else {
636
631
throw e ;
637
632
}
@@ -1793,21 +1788,23 @@ PTuple waitpid(VirtualFrame frame, long pid, int options,
1793
1788
@ CachedLibrary ("getPosixSupport()" ) PosixSupportLibrary posixLib ,
1794
1789
@ Cached BranchProfile errorProfile ) {
1795
1790
gil .release (true );
1796
- while ( true ) {
1797
- try {
1798
- long [] result = posixLib . waitpid ( getPosixSupport (), pid , options );
1799
- gil . acquire ( );
1800
- return factory ().createTuple (new Object []{result [0 ], result [1 ]});
1801
- } catch (PosixException e ) {
1802
- errorProfile .enter ();
1803
- gil . acquire ();
1804
- if ( e . getErrorCode () == OSErrorEnum . EINTR . getNumber ()) {
1805
- PythonContext . triggerAsyncActions ( this );
1806
- gil .release ( true );
1807
- } else {
1808
- throw raiseOSErrorFromPosixException ( frame , e );
1791
+ try {
1792
+ while ( true ) {
1793
+ try {
1794
+ long [] result = posixLib . waitpid ( getPosixSupport (), pid , options );
1795
+ return factory ().createTuple (new Object []{result [0 ], result [1 ]});
1796
+ } catch (PosixException e ) {
1797
+ errorProfile .enter ();
1798
+ if ( e . getErrorCode () == OSErrorEnum . EINTR . getNumber ()) {
1799
+ PythonContext . triggerAsyncActions ( this );
1800
+ } else {
1801
+ gil .acquire ( );
1802
+ throw raiseOSErrorFromPosixException ( frame , e );
1803
+ }
1809
1804
}
1810
1805
}
1806
+ } finally {
1807
+ gil .acquire ();
1811
1808
}
1812
1809
}
1813
1810
}
@@ -1959,9 +1956,9 @@ int system(PBytes command,
1959
1956
// conversions for emulated backend because the bytes version after fsencode conversion
1960
1957
// is subject to sys.audit.
1961
1958
auditNode .audit ("os.system" , command );
1959
+ byte [] bytes = toBytesNode .execute (command );
1962
1960
gil .release (true );
1963
1961
try {
1964
- byte [] bytes = toBytesNode .execute (command );
1965
1962
Object cmdOpaque = posixLib .createPathFromBytes (getPosixSupport (), bytes );
1966
1963
return posixLib .system (getPosixSupport (), cmdOpaque );
1967
1964
} finally {
0 commit comments