There’s some TTY-weirdness going on when I try to print a multi-line strings to stdout
or stderr
from a spawned task.
Sometimes when printing a string with multiple line-breaks in it (although not always), the printed string is truncated prematurely at a line break character and the rest of the string is not printed.
I’m guessing this is some interaction between task yielding in Julia and printing out to a TTY stream, but I’m hoping someone with more information here can figure out what’s going on.
On Julia 1.9.1 running on Debian 11, with JULIA_NUM_THREADS=4
, for example, when running
julia> channel = Channel(; spawn=true) do ch
while isopen(ch)
println(take!(ch)::String)
end
end
and repeatedly evaluating (via Up + Enter in the REPL)
julia> put!(channel, join(string.(1:10), '\n'));
will most often yield the following output
julia> put!(channel, join(string.(1:10), '\n'));
1
2
3
4
5
6
7
8
9
10
but occasionally (but not always) will display
julia> put!(channel, join(string.(1:10), '\n'));
1
2
3
4
5
6
7
8
9
This happens when printing to stderr
as well as stdout
. This problem doesn’t seem occur when not spawning a task on a separate thread, via
julia> channel = Channel() do ch
while isopen(ch)
println(take!(ch)::String)
end
end
or when setting JULIA_NUM_THREADS=1
.
I’ve tried and failed to recreate this behaviour when running Julia 1.9.1 on MacOS 13.1, so this seems to be a linux issue perhaps.
Does anyone have any idea what’s going on here? Thanks in advance.