@@ -22,8 +22,7 @@ class JuliaMagics(Magics):
22
22
def julia (self , line , cell = None ):
23
23
code = line if cell is None else cell
24
24
ans = Main .seval ('begin\n ' + code + '\n end' )
25
- Base .flush (Base .stdout )
26
- Base .flush (Base .stderr )
25
+ PythonCall ._flush_stdio ()
27
26
if not code .strip ().endswith (';' ):
28
27
return ans
29
28
@@ -35,10 +34,21 @@ def load_ipython_extension(ip):
35
34
PythonCall .seval ("""begin
36
35
const _redirected_stdout = redirect_stdout()
37
36
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"))
40
39
const _redirect_stdout_task = @async write($_py_stdout, $_redirected_stdout)
41
40
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
42
50
pushdisplay(PythonDisplay())
43
51
pushdisplay(IPythonDisplay())
52
+ nothing
44
53
end""" )
54
+ ip .events .register ('post_execute' , PythonCall ._flush_stdio )
0 commit comments