Skip to content

Commit 97929f2

Browse files
committed
[GR-7165] [hotfix] Let the async handler threads shut down if the context closes
PullRequest: graalpython/396
2 parents 40d1c30 + 0b44f09 commit 97929f2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.concurrent.ConcurrentLinkedQueue;
4545
import java.util.concurrent.Executors;
4646
import java.util.concurrent.ScheduledExecutorService;
47+
import java.util.concurrent.ThreadFactory;
4748
import java.util.concurrent.TimeUnit;
4849
import java.util.concurrent.locks.Lock;
4950
import java.util.concurrent.locks.ReentrantLock;
@@ -91,7 +92,13 @@ default int frameIndex() {
9192
}
9293
}
9394

94-
private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(2);
95+
private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(2, new ThreadFactory() {
96+
public Thread newThread(Runnable r) {
97+
Thread t = Executors.defaultThreadFactory().newThread(r);
98+
t.setDaemon(true);
99+
return t;
100+
}
101+
});
95102
private final ConcurrentLinkedQueue<AsyncAction> scheduledActions = new ConcurrentLinkedQueue<>();
96103
private boolean hasScheduledAction = false;
97104
private final Lock executingScheduledActions = new ReentrantLock();
@@ -224,4 +231,8 @@ private void processAsyncActions() {
224231
}
225232
}
226233
}
234+
235+
public void shutdown() {
236+
executorService.shutdownNow();
237+
}
227238
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ public void deregisterShutdownHook(Object callable) {
288288

289289
@TruffleBoundary
290290
public void runShutdownHooks() {
291+
handler.shutdown();
291292
for (CallTarget f : atExitHooks.values()) {
292293
f.call();
293294
}

0 commit comments

Comments
 (0)