Skip to content

Commit 4a688d5

Browse files
committed
Add error checking to previous commit.
1 parent 9a30d2d commit 4a688d5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Source/PythonEngine.pas

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9651,7 +9651,8 @@ procedure TPythonThread.Execute;
96519651
finally
96529652
PyGILState_Release(gilstate);
96539653
end;
9654-
end else
9654+
end
9655+
else
96559656
begin
96569657
gilstate := PyGILState_Ensure();
96579658
global_state := PyThreadState_Get;
@@ -9665,22 +9666,26 @@ procedure TPythonThread.Execute;
96659666
PyStatus_Exception(Py_NewInterpreterFromConfig(@fThreadState, @Config))
96669667
then
96679668
fThreadState := Py_NewInterpreter
9668-
else
9669+
else if Assigned(IOPythonModule) then
96699670
// flag IOPythonModule as per interpreter GIL compatible
96709671
TPythonModule(IOPythonModule).MultInterpretersSupport := mmiPerInterpreterGIL;
96719672

96729673
if Assigned(fThreadState) then
96739674
begin
96749675
PyThreadState_Swap(fThreadState);
96759676
// Redirect IO
9676-
TPythonModule(IOPythonModule).InitializeForNewInterpreter;
9677-
DoRedirectIO;
9677+
if RedirectIO and Assigned(IOPythonModule) then
9678+
begin
9679+
TPythonModule(IOPythonModule).InitializeForNewInterpreter;
9680+
DoRedirectIO;
9681+
end;
96789682
// Execute the python code
96799683
ExecuteWithPython;
96809684
Py_EndInterpreter( fThreadState);
96819685
PyThreadState_Swap(global_state);
96829686
PyGILState_Release(gilstate);
9683-
end else
9687+
end
9688+
else
96849689
raise EPythonError.Create(SCannotCreateThreadState);
96859690
end;
96869691
end;

0 commit comments

Comments
 (0)