File tree Expand file tree Collapse file tree 3 files changed +27
-4
lines changed
graalpython/com.oracle.graal.python/src/com/oracle/graal/python Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -208,8 +208,7 @@ public NodeFactory getNodeFactory() {
208
208
209
209
@ Override
210
210
protected void finalizeContext (PythonContext context ) {
211
- context .shutdownThreads ();
212
- context .runShutdownHooks ();
211
+ context .finalizeContext ();
213
212
super .finalizeContext (context );
214
213
}
215
214
Original file line number Diff line number Diff line change 52
52
import java .util .Date ;
53
53
import java .util .List ;
54
54
55
+ import com .oracle .truffle .api .dsl .CachedContext ;
55
56
import org .graalvm .nativeimage .ImageInfo ;
56
57
57
58
import com .oracle .graal .python .PythonLanguage ;
@@ -492,4 +493,15 @@ protected LookupAndCallUnaryNode createWithoutError() {
492
493
return LookupAndCallUnaryNode .create (__SIZEOF__ );
493
494
}
494
495
}
496
+
497
+ @ Builtin (name = "is_finalizing" )
498
+ @ GenerateNodeFactory
499
+ public abstract static class IsFinalizingNode extends PythonBuiltinNode {
500
+ @ Specialization
501
+ static boolean doGeneric (
502
+ @ CachedContext (PythonLanguage .class ) PythonContext context ) {
503
+ return context .isFinalizing ();
504
+ }
505
+ }
506
+
495
507
}
Original file line number Diff line number Diff line change 107
107
108
108
public final class PythonContext {
109
109
private static final TruffleLogger LOGGER = PythonLanguage .getLogger (PythonContext .class );
110
+ private volatile boolean finalizing ;
110
111
111
112
private static final class PythonThreadState {
112
113
@@ -717,7 +718,14 @@ public void deregisterShutdownHook(Object callable) {
717
718
}
718
719
719
720
@ TruffleBoundary
720
- public void runShutdownHooks () {
721
+ public void finalizeContext () {
722
+ finalizing = true ;
723
+ shutdownThreads ();
724
+ runShutdownHooks ();
725
+ }
726
+
727
+ @ TruffleBoundary
728
+ private void runShutdownHooks () {
721
729
handler .shutdown ();
722
730
// run atExitHooks in reverse order they were registered
723
731
MapCursor <Object , AtExitHook > cursor = atExitHooks .getEntries ();
@@ -741,7 +749,7 @@ public void runShutdownHooks() {
741
749
}
742
750
743
751
@ TruffleBoundary
744
- public void shutdownThreads () {
752
+ private void shutdownThreads () {
745
753
LOGGER .fine ("shutting down threads" );
746
754
PDict importedModules = getImportedModules ();
747
755
HashingStorage dictStorage = GetDictStorageNode .getUncached ().execute (importedModules );
@@ -1105,4 +1113,8 @@ public void setGcEnabled(boolean flag) {
1105
1113
public AsyncHandler .SharedFinalizer getSharedFinalizer () {
1106
1114
return sharedFinalizer ;
1107
1115
}
1116
+
1117
+ public boolean isFinalizing () {
1118
+ return finalizing ;
1119
+ }
1108
1120
}
You can’t perform that action at this time.
0 commit comments