Skip to content

Commit feb8a74

Browse files
committed
Don't release the gil if nobody is waiting for it
1 parent 08c0c19 commit feb8a74

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/AsyncHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ private GilReleaseScheduler(PythonContext ctx) {
348348

349349
@Override
350350
public void run() {
351+
if (!ctx.gilHasQueuedThreads()) {
352+
// Don't release the gil if nobody is waiting for it
353+
return;
354+
}
351355
Thread gilOwner = ctx.getGilOwner();
352356
if (gilOwner != null) {
353357
synchronized (this) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,6 +2242,13 @@ Thread getGilOwner() {
22422242
return globalInterpreterLock.getOwner();
22432243
}
22442244

2245+
/**
2246+
* Should not be used outside of {@link AsyncHandler}
2247+
*/
2248+
boolean gilHasQueuedThreads() {
2249+
return globalInterpreterLock.hasQueuedThreads();
2250+
}
2251+
22452252
/**
22462253
* Should not be called directly.
22472254
*

0 commit comments

Comments
 (0)