# Multi Line TTY printing weirdness from the non-main thread

**URL:** <https://discourse.julialang.org/t/multi-line-tty-printing-weirdness-from-the-non-main-thread/100423>\
**Category:** General Usage\
**Tags:** question, repl\
**Created:** [June 15, 2023, 9:34pm UTC](https://discourse.julialang.org/t/multi-line-tty-printing-weirdness-from-the-non-main-thread/100423 "2023-06-15T21:34:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![curtd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curtd/32/15868_2.png) [@curtd](https://discourse.julialang.org/u/curtd)\
**Post date:** [June 15, 2023, 9:34pm UTC](https://discourse.julialang.org/t/multi-line-tty-printing-weirdness-from-the-non-main-thread/100423/1 "2023-06-15T21:34:27Z")

</div>

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
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
julia> put!(channel, join(string.(1:10), '\n'));

```

will most often yield the following output

```julia
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
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
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.

---

<div class="post-metadata">

**Author:** ![caleb-allen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/caleb-allen/32/14054_2.png) [@caleb-allen](https://discourse.julialang.org/u/caleb-allen)\
**Post date:** [July 10, 2023, 11:24am UTC](https://discourse.julialang.org/t/multi-line-tty-printing-weirdness-from-the-non-main-thread/100423/2 "2023-07-10T11:24:27Z")

</div>

Do you ever encounter this issue when setting the thread to `:interactive`?
