Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions inst/private/python_header.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Copyright (C) 2014-2017, 2019, 2021-2024 Colin B. Macdonald
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2014-2017, 2019, 2021-2024, 2026 Colin B. Macdonald
# Copyright (C) 2019 Mike Miller
# Copyright (C) 2020 Tianyu Chen (billchenchina)
# Copyright (C) 2021 Johannes Maria Frank
# Copyright (C) 2022 Chris Gorman
# Copyright (C) 2022 Alex Vong
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2026 Dmitri A. Sergatskov

# In some cases this code is fed into stdin: two blank lines between
# try-except blocks, no blank lines within each block.
Expand All @@ -27,6 +28,10 @@ def echo_exception_stdout(mystr):
print("<item>\n<f>1003</f>")
print("<f>" + exception_str.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;") + "</f>\n</item>")
print("</list>\n</output_block>\n")
# Python 3.13 and newer do not flush stdout when an exception escapes to
# the interactive interpreter, so callers that "raise" after us would
# leave this block stuck in the buffer (Octave then waits forever).
sys.stdout.flush()

try:
import sympy
Expand Down
9 changes: 7 additions & 2 deletions inst/private/python_ipc_popen2.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
%% SPDX-License-Identifier: GPL-3.0-or-later
%% Copyright (C) 2014-2019, 2022, 2024 Colin B. Macdonald
%% Copyright (C) 2014-2019, 2022, 2024, 2026 Colin B. Macdonald
%% Copyright (C) 2018, 2020 Mike Miller
%% Copyright (C) 2022 Alex Vong
%% Copyright (C) 2026 Dmitri A. Sergatskov
%%
%% This file is part of OctSymPy.
%%
Expand Down Expand Up @@ -87,7 +88,11 @@
assert_have_python_and_sympy (pyexec)

% formatting matters
args = {'-i', '-c', 'import sys; sys.ps1=''''; sys.ps2='''''};
% '-u': unbuffered stdout: since Python 3.13, the interactive
% interpreter does not flush stdout when an exception escapes to
% the top level, so an output block could sit in the child's
% buffer while we wait forever for it (Issue: pipe deadlock).
args = {'-u', '-i', '-c', 'import sys; sys.ps1=''''; sys.ps2='''''};
[fin, fout, pid] = popen2 (pyexec, args);
fflush (stdout);

Expand Down