Skip to content

Commit 9a30d2d

Browse files
committed
Support stdout redirection in sub-interpreters.
1 parent b5ef2c1 commit 9a30d2d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Source/PythonEngine.pas

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9664,11 +9664,18 @@ procedure TPythonThread.Execute;
96649664
((FMajorVersion = 3) and (FMinorVersion < 12)) or
96659665
PyStatus_Exception(Py_NewInterpreterFromConfig(@fThreadState, @Config))
96669666
then
9667-
fThreadState := Py_NewInterpreter;
9667+
fThreadState := Py_NewInterpreter
9668+
else
9669+
// flag IOPythonModule as per interpreter GIL compatible
9670+
TPythonModule(IOPythonModule).MultInterpretersSupport := mmiPerInterpreterGIL;
96689671

9669-
if Assigned( fThreadState) then
9672+
if Assigned(fThreadState) then
96709673
begin
96719674
PyThreadState_Swap(fThreadState);
9675+
// Redirect IO
9676+
TPythonModule(IOPythonModule).InitializeForNewInterpreter;
9677+
DoRedirectIO;
9678+
// Execute the python code
96729679
ExecuteWithPython;
96739680
Py_EndInterpreter( fThreadState);
96749681
PyThreadState_Swap(global_state);

0 commit comments

Comments
 (0)