Skip to content

Commit 26a728a

Browse files
committed
Prevent multiple Python interpreter initializations
Adds a check to skip starting a new Python interpreter if one is already running. Returns a message to the caller and logs the event when initialization is skipped.
1 parent 1e8c078 commit 26a728a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/serious_python_android/lib/src/cpython.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ Future<String> runPythonProgramInIsolate(List<Object> arguments) async {
122122
cpython.Py_Initialize();
123123
_pyLog("after Py_Initialize()");
124124
} else {
125-
_pyLog("Python already initialized; reusing interpreter");
125+
// Interpreter is already running; skip launching another run and let the
126+
// previously started script continue. Return a message for the caller.
127+
_pyLog("Python already initialized; skipping new run");
128+
final msg = "Python already initialized; skipped starting a new run.";
129+
sendPort.send(msg);
130+
return msg;
126131
}
127132

128133
var result = "";

0 commit comments

Comments
 (0)