Skip to content

Commit 6823613

Browse files
committed
Move Py_FinalizeEx call to end of isolate function
Removed AppLifecycleListener-based finalization and now explicitly call cpython.Py_FinalizeEx() at the end of runPythonProgramInIsolate. This ensures Python finalization occurs after the program finishes, improving resource management.
1 parent 78c3e0f commit 6823613

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/serious_python_android/lib/src/cpython.dart

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,6 @@ Future<String> runPythonProgramInIsolate(List<Object> arguments) async {
9696
_debug("after Py_Initialize()");
9797
}
9898

99-
AppLifecycleListener(onDetach: () {
100-
_debug("AppLifecycleListener: onDetach");
101-
_withGIL(cpython, () {
102-
if (cpython.Py_IsInitialized() != 0) {
103-
cpython.Py_FinalizeEx();
104-
_debug("after Py_FinalizeEx()");
105-
}
106-
});
107-
});
108-
10999
final result = _withGIL(cpython, () {
110100
final logcatSetupError = _setupLogcatForwarding(cpython);
111101
if (logcatSetupError != null) {
@@ -140,6 +130,9 @@ Future<String> runPythonProgramInIsolate(List<Object> arguments) async {
140130

141131
_debug("Python program finished");
142132

133+
cpython.Py_FinalizeEx();
134+
_debug("after Py_FinalizeEx()");
135+
143136
sendPort.send(result);
144137

145138
return result;

0 commit comments

Comments
 (0)