in the MWE below, “start” is never displayed. is there a way to make it so?
using GLMakie
f = Figure()
b = Button(f[1,1], label="foo")
l = Label(f[1,2], "")
on(b.clicks) do _
l.text[] = "start"
sleep(1) # long running calculation
l.text[] = "finish"
end
The problem is sleep
is running in the same task as the GUI updates, so until this function returns no graphical updates can happen. The solution is to launch the long-running function in its own task:
using GLMakie
f = Figure()
b = Button(f[1,1], label="foo")
l = Label(f[1,2], "")
on(b.clicks) do _
l.text[] = "start"
@async begin
sleep(1) # long running calculation
l.text[] = "finish"
end
end
1 Like
thanks! and in my case at least Threads.@spawn
instead throws a seg fault, perhaps because i switch Makie backends in the task.
GLMakie isn’t thread safe, but a new task on the same thread works fine. I’m pretty sure I saw this in the documentation, but I can’t find the link now.