-
-
Notifications
You must be signed in to change notification settings - Fork 418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement Base.redirect_{stdout,stderr,stdin} #641
Conversation
@@ -100,13 +100,13 @@ function init(args) | |||
start_heartbeat(heartbeat[]) | |||
if capture_stdout | |||
read_stdout[], = redirect_stdout() | |||
eval(Base, :(STDOUT = $(IJuliaStdio(STDOUT,"stdout")))) | |||
redirect_stdout(IJuliaStdio(STDOUT,"stdout")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are calling redirect_stdout
twice...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see, you're calling the overloaded method below...
Datapoint: this fixes TraceCalls in IJulia (cstjean/TraceCalls.jl#60) which makes me happy. |
src/stdio.jl
Outdated
@@ -24,6 +24,9 @@ if VERSION >= v"0.7.0-DEV.1472" # Julia PR #23271 | |||
Base.unwrapcontext(io::IJuliaStdio) = Base.unwrapcontext(io.io) | |||
end | |||
Base.setup_stdio(io::IJuliaStdio, readable::Bool) = Base.setup_stdio(io.io.io, readable) | |||
Base.redirect_stdout(io::IJuliaStdio) = (eval(Base, :(STDOUT = $io)); io) | |||
Base.redirect_stderr(io::IJuliaStdio) = (eval(Base, :(STDERR = $io)); io) | |||
Base.redirect_stdin(io::IJuliaStdio) = (eval(Base, :(STDIN = $io)); io) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem right to me. It's not returning the documented (rd, wr)
pair...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation seems to be wrong in this case. Calling redirect_stdout(STDERR)
, for example, just returns STDERR
. See: https://github.com/JuliaLang/julia/blob/v0.6.2/base/stream.jl#L1031
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's only called for restoring the original STDOUT stream in redirect_*
. In that case, however, probably check that this is the case. Something like:
for s in ("stdout", "stderr", "stdin")
f = Symbol("redirect_", s)
S = QuoteNode(Symbol(uppercase(s)))
@eval function Base.$f(io::IJuliaStdio)
io[:jupyter_stream] != $s && error("expecting ", $s, " stream)
eval(Base, Expr(:=, $S, :io))
return io, io
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can do that. It does seem a bit odd for the return type to be inconsistent with the Base implementation of redirect_stdout(STDOUT)
, though, doesn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't notice that redirect_stdout(STDOUT)
returned only a single stream. That seems like a bug in base, since Ah, now I see that you filed an issue for that.redirect_stdout
is documented to return two streams.
But sure, in that case do return io
rather than return io, io
. But we should still check that it is restoring the correct stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done
Datapoint: Before this patch, I got error #640 on the following in jupyter. After this patch, the julia kernel hangs somewhere (no CPU consumption; still reacts to "restart kernel", but does not react to "interrupt kernel"). On the REPL, this works like expected.
|
Fixes #640. Please let me know if this isn't the appropriate solution to the problem.