Suppressor not working with Julia 1.7.1 and SimpleGraphAlgorithms
I recently upgraded to Julia 1.7.1 and I noticed that Suppressor.jl is not working anymore with some code where it was previously working just fine. Here is a minimal working example:
julia> using SimpleGraphs, SimpleGraphAlgorithms, Suppressor
julia> G = SimpleGraph([0 1; 1 0])
SimpleGraph{Int64} (n=2, m=1)
julia> @suppress vertex_color(G)
I was expecting the output to just be
Dict{Int64, Int64} with 2 entries:
2 => 1
1 => 2
but instead, I get a very verbose output from the solver that computes the vertex coloring. This same code worked fine in Julia 1.6.3, so I'm not sure what has changed.
When running from the command line, the second and subsequent times that I run the last line, I get the expected output. However, when I'm in a Jupyter notebook, I keep getting the verbose text every time.
~Hi Steve, I just run into the same issue, a simple fix is to define the following in your code~
Base.get(::Base.PipeEndpoint, key::Symbol, default) = key === :color ? Base.get_have_color() : default
~but I think this cannot be added to a package right now, since it might break other things which I'm not sure about. I think this is a Julia issue, just filed an issue (above) in JuliaLang repo.~
I misunderstand part of your issue, I think the other part that has been changed is the return value of redirect_stdout, it is now only one Pipe object instead of two. so this line is not correct anymore
https://github.com/JuliaIO/Suppressor.jl/blob/3cb95ef55a85172e72054f2342c81fa0044b3912/src/Suppressor.jl#L18
I think one could just use the following on 1.7 without using Suppress now
redirect_stdout(Pipe()) do
vertex_color(G)
end
(it's a bit of surprise that Pipe() is not a default value for redirect_stdout(f)...)
Thanks Roger! That work around helps, but it doesn't solve the problem for more complicated use cases. For example, if I put vertex_color inside another function, then it doesn't seem to work. For example, the following gives me verbose output in my jupyter notebook. (I didn't try command line.)
using SimpleGraphs, SimpleGraphAlgorithms
G = SimpleGraph([0 1; 1 0])
function quiet_color(G)
redirect_stdout(Pipe()) do
vertex_color(G)
end
end
quiet_color(G)
I don't understand why redirect_stdout has different behavior inside or outside of a function.
I think to ignore the stdout from C, one needs to redirect it to devnull, so the following code should do the trick, but I'm not sure why the printing is pasted to REPL when exiting, but this should work in scripts.
using SimpleGraphs, SimpleGraphAlgorithms
G = SimpleGraph([0 1; 1 0])
function quiet_color(G)
redirect_stdout(devnull) do
vertex_color(G)
end
end
quiet_color(G)