Skip to content
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

Pipe redirect solution seems to break code that writes to STDOUT #1245

Open
rofinn opened this issue Feb 21, 2020 · 2 comments
Open

Pipe redirect solution seems to break code that writes to STDOUT #1245

rofinn opened this issue Feb 21, 2020 · 2 comments

Comments

@rofinn
Copy link
Contributor

rofinn commented Feb 21, 2020

I've tested this on julia 1.0.5 and 1.3.1 with the latest release.

[debug | root]: Something to help you track down a bug.ERROR: ArgumentError: stream is closed or unusable
│    Stacktrace:
│     [1] check_open at ./stream.jl:252 [inlined]
│     [2] uv_write_async(::Base.PipeEndpoint, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:800
│     [3] uv_write(::Base.PipeEndpoint, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:774
│     [4] unsafe_write(::Base.PipeEndpoint, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:830
│     [5] macro expansion at ./gcutils.jl:87 [inlined]
│     [6] write at ./strings/io.jl:164 [inlined]
│     [7] print at ./strings/io.jl:166 [inlined]
│     [8] #with_output_color#661(::Bool, ::Function, ::Function, ::Symbol, ::Base.PipeEndpoint, ::String) at ./util.jl:370
│     [9] #with_output_color at ./none:0 [inlined]
│     [10] #printstyled#662 at ./util.jl:398 [inlined]
│     [11] (::getfield(Base, Symbol("#kw##printstyled")))(::NamedTuple{(:color,),Tuple{Symbol}}, ::typeof(printstyled), ::Base.PipeEndpoint, ::String) at ./none:0
│     [12] emit(::DefaultHandler{DefaultFormatter,Base.PipeEndpoint}, ::DefaultRecord) at /Users/rory/.julia/packages/Memento/UgJr2/src/handlers.jl:212
│     [13] log(::DefaultHandler{DefaultFormatter,Base.PipeEndpoint}, ::DefaultRecord) at /Users/rory/.julia/packages/Memento/UgJr2/src/handlers.jl:46
│     [14] log(::Logger, ::DefaultRecord) at /Users/rory/.julia/packages/Memento/UgJr2/src/loggers.jl:358
│     [15] _log(::Logger, ::String, ::String) at /Users/rory/.julia/packages/Memento/UgJr2/src/loggers.jl:403
│     [16] log(::Logger, ::String, ::String) at /Users/rory/.julia/packages/Memento/UgJr2/src/loggers.jl:382
│     [17] debug(::Logger, ::String) at /Users/rory/.julia/packages/Memento/UgJr2/src/loggers.jl:418
│     [18] top-level scope at none:0
@mortenpi
Copy link
Member

Do you have an MWE by any chance? I tried the following and it seems to work fine:

```@example
@info "HAHAHA"
println(stdout, "AA")
2 + 2
nothing
```

```jldoctest
julia> println(stdout, "AAA")
AAA
```

@rofinn
Copy link
Contributor Author

rofinn commented Feb 24, 2020

Seems to be an issue with redirection of IO in types that are saved in a struct that in turn lives in a package global dict. The smallest minimal example I could find is:

Minimal package example

module MyPkg

struct Foo
    io::IO
end

Foo() = Foo(stdout)
emit(f::Foo) = printstyled(f.io, "AAA");

const _foos = Dict{AbstractString, Foo}(
    "root" => Foo(),
)

# Initialize root Foo() at runtime, so we don't use a stale `stdout` reference after precompilation.
function __init__()
    Memento._foos["root"] = Foo()
end

Doctest failure code

julia> using MyPkg

julia> MyPkg._foos["root"] = MyPkg.Foo()

julia> MyPkg.emit(MyPkg._foos["root"])
AAA

Throws a similar stream closed error.

│ Expected output:
│
│ AAA
│
│   diff =
│    AAAERROR: IOError: stream is closed or unusable
│    Stacktrace:
│     [1] check_open at ./stream.jl:328 [inlined]
│     [2] uv_write_async(::Base.PipeEndpoint, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:961
│     [3] uv_write(::Base.PipeEndpoint, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:924
│     [4] unsafe_write(::Base.PipeEndpoint, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:1007
│     [5] macro expansion at ./gcutils.jl:91 [inlined]
│     [6] write at ./strings/io.jl:186 [inlined]
│     [7] print at ./strings/io.jl:188 [inlined]
│     [8] #with_output_color#707(::Bool, ::typeof(Base.with_output_color), ::Function, ::Symbol, ::Base.PipeEndpoint, ::String) at ./util.jl:369
│     [9] #with_output_color at ./none:0 [inlined]
│     [10] #printstyled#708 at ./util.jl:397 [inlined]
│     [11] printstyled(::Base.PipeEndpoint, ::String) at ./util.jl:397
│     [12] emit(::MyPkg.Foo) at /Users/rory/repos/invenia/MyPkg.jl/src/MyPkg.jl:68
│     [13] top-level scope at none:4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants