Skip to content

Commit c2af996

Browse files
author
Christopher Doris
committed
fix redirection on Julia 1.6
1 parent 47dfa77 commit c2af996

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

pysrc/juliacall/ipython.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def julia(self, line, cell=None):
5151
# run the code
5252
ans = Main.seval('begin\n' + code + '\nend')
5353
# flush stderr/stdout
54-
PythonCall._flush_stdio()
54+
PythonCall._ipython._flush_stdio()
5555
# copy variables back to Python
5656
# only copy those which are new or have changed value
5757
for k in outvars + syncvars:
@@ -74,18 +74,22 @@ def load_ipython_extension(ip):
7474
end
7575
end""")
7676
else:
77+
# In Julia 1.7+ redirect_stdout() returns a Pipe object. Earlier versions of Julia
78+
# just return a tuple of the two pipe ends. This is why we have [1] and [2] below.
79+
# They can be dropped on earlier versions.
7780
PythonCall.seval("""module _ipython
81+
using ..PythonCall
7882
const _redirected_stdout = redirect_stdout()
7983
const _redirected_stderr = redirect_stderr()
8084
const _py_stdout = PyIO(pyimport("sys" => "stdout"); line_buffering=true)
8185
const _py_stderr = PyIO(pyimport("sys" => "stderr"); line_buffering=true)
82-
const _redirect_stdout_task = @async write($_py_stdout, $_redirected_stdout)
83-
const _redirect_stderr_task = @async write($_py_stderr, $_redirected_stderr)
86+
const _redirect_stdout_task = @async write($_py_stdout, $_redirected_stdout[1])
87+
const _redirect_stderr_task = @async write($_py_stderr, $_redirected_stderr[1])
8488
function _flush_stdio()
8589
flush(stderr)
8690
flush(stdout)
87-
flush(_redirected_stderr)
88-
flush(_redirected_stdout)
91+
flush(_redirected_stderr[2])
92+
flush(_redirected_stdout[2])
8993
flush(_py_stderr)
9094
flush(_py_stdout)
9195
nothing

0 commit comments

Comments
 (0)