Skip to content

Strange interaction with redirect_stdout #181

@jonathanBieler

Description

@jonathanBieler

I'm trying to display Julia output in a GtkWidget but it's kind of slow and feels sluggish. I put together this minimal example (coming from IJulia):

function send_stream(rd::IO, name::AbstractString)
    nb = nb_available(rd)
    if nb > 0
        d = readbytes(rd, nb)
        s = try
            bytestring(d)
        catch
        end
        #do something with s
    end
end

function watch_stream(rd::IO, name::AbstractString)
    try
        while !eof(rd) # blocks until something is available
            send_stream(rd, name)
            sleep(0.01) # a little delay to accumulate output
        end
    catch e
        # the IPython manager may send us a SIGINT if the user
        # chooses to interrupt the kernel; don't crash on this
        if isa(e, InterruptException)
            watch_stream(rd, name)
        else
            rethrow()
        end
    end
end

global read_stdout
read_stdout, wr = redirect_stdout()
function watch_stdio()
    @async watch_stream(read_stdout, "stdout")
end
watch_stdio()

Calling a print command (e.g. print(randn(100))) in the REPL is very fast (after compilation). However as soon as you use Gtk (using Gtk) it becomes very slow (seems like 2 seconds on my computer). I've tried with a few other packages but Gtk seems to be the only one interacting.

Any idea what's going on and how to fix that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions