Skip to content

Commit aa32d6b

Browse files
committed
Comment out GIL management in _withGIL function
The GIL acquisition and release logic in _withGIL has been commented out, and the function now directly executes the action. Interpreter finalization code in runPythonProgramInIsolate remains commented out, with updated comments explaining the rationale.
1 parent 919926d commit aa32d6b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/serious_python_android/lib/src/cpython.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ void _debug(String message) {
4747
}
4848

4949
T _withGIL<T>(CPython cpython, T Function() action) {
50-
final gil = cpython.PyGILState_Ensure();
51-
try {
52-
return action();
53-
} finally {
54-
cpython.PyGILState_Release(gil);
55-
}
50+
// final gil = cpython.PyGILState_Ensure();
51+
// try {
52+
// return action();
53+
// } finally {
54+
// cpython.PyGILState_Release(gil);
55+
// }
56+
return action();
5657
}
5758

5859
/// Finalize interpreter safely without releasing GIL afterwards (Py_FinalizeEx
@@ -146,8 +147,9 @@ Future<String> runPythonProgramInIsolate(List<Object> arguments) async {
146147
return "";
147148
});
148149
} finally {
149-
// Keep interpreter alive between runs; finalizing caused crashes when
150-
// re-initializing extension modules (e.g. _ctypes) on Android.
150+
// Finalize interpreter so subsequent runs start clean and GIL is free.
151+
// _finalizeInterpreter(cpython);
152+
// _cpython = null;
151153
}
152154

153155
sendPort.send(result);

0 commit comments

Comments
 (0)