@@ -22,8 +22,7 @@ class JuliaMagics(Magics):
2222 def julia (self , line , cell = None ):
2323 code = line if cell is None else cell
2424 ans = Main .seval ('begin\n ' + code + '\n end' )
25- Base .flush (Base .stdout )
26- Base .flush (Base .stderr )
25+ PythonCall ._flush_stdio ()
2726 if not code .strip ().endswith (';' ):
2827 return ans
2928
@@ -35,10 +34,21 @@ def load_ipython_extension(ip):
3534 PythonCall .seval ("""begin
3635 const _redirected_stdout = redirect_stdout()
3736 const _redirected_stderr = redirect_stderr()
38- const _py_stdout = PyIO(pyimport("sys" => "stdout"), buflen=1 )
39- const _py_stderr = PyIO(pyimport("sys" => "stderr"), buflen=1 )
37+ const _py_stdout = PyIO(pyimport("sys" => "stdout"))
38+ const _py_stderr = PyIO(pyimport("sys" => "stderr"))
4039 const _redirect_stdout_task = @async write($_py_stdout, $_redirected_stdout)
4140 const _redirect_stderr_task = @async write($_py_stderr, $_redirected_stderr)
41+ function _flush_stdio()
42+ flush(stderr)
43+ flush(stdout)
44+ flush(_redirected_stderr)
45+ flush(_redirected_stdout)
46+ flush(_py_stderr)
47+ flush(_py_stdout)
48+ nothing
49+ end
4250 pushdisplay(PythonDisplay())
4351 pushdisplay(IPythonDisplay())
52+ nothing
4453 end""" )
54+ ip .events .register ('post_execute' , PythonCall ._flush_stdio )
0 commit comments