GLMakie with blocking thread

Hello good people!

I am trying to plot and process data in Julia with GLMakie. The data is communicated via a gRPC call and as I am unable to find suitable Julia packages for handling this, I have a python module that handles the communication. I’m using PyCall for interacting with Python.
The problem that I am bumping in to is that the Python service “eats” the thread I’m on, so I started that in a separate thread. When I do this, the Makie window becomes unresponsive. Do you have any pointers as to what may be the problem and how to navigate around that?
MWE:

using GLMakie

function mwe()
    fig = GLMakie.Figure()
    gl = fig[1, 1] = GridLayout()
    Toggle(gl[1, 1], active = false)
    display(fig)
    sleep(1)
    Threads.@spawn begin
        while(true)
        end
    end
end

The Toggle will not work in the MWE above and the GUI will freeze.

This works on my PC, could it be, that you only run julia with one thread?
Make sure Threads.nthreads() > 1.
If there’s only one thread, you will need a yield to allow any other task to work.
Also, be aware that GLMakie isn’t threadsafe, so you can’t just update any plot from another thread!
You will need to push the updates to a channel, or something like that:

function mwe()
   channel = Channel(Inf) do channel
       fig = GLMakie.Figure()
       gl = fig[1, 1] = GridLayout()
       ax = Axis(gl[2, 1])
       t = Toggle(gl[1, 1], active=false, tellwidth=false)
       splot = scatter!(ax, rand(Point2f, 10))
       display(fig)
       task = @async for update! in channel 
           update!(splot) # pass Makie objects in here
       end
       wait(task)
   end
       
   Threads.@spawn begin
       while true 
           push!(channel, (plot)-> begin 
               plot[1] = rand(Point2f, 10)
           end)
           sleep(1/25)
       end
   end
end

mwe()

Thank you for the reply!
That’s very interesting, I did double check and

julia> Threads.nthreads()
4

I wonder why it works on your system but freezes on mine.

Actually, the code you posted works for me, but not the mwe I posted myself.
Thanks again!