# Updating Label value twice in the same Makie event handler

**URL:** <https://discourse.julialang.org/t/updating-label-value-twice-in-the-same-makie-event-handler/122918>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [November 22, 2024, 12:16am UTC](https://discourse.julialang.org/t/updating-label-value-twice-in-the-same-makie-event-handler/122918 "2024-11-22T00:16:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)\
**Post date:** [November 22, 2024, 12:16am UTC](https://discourse.julialang.org/t/updating-label-value-twice-in-the-same-makie-event-handler/122918/1 "2024-11-22T00:16:37Z")

</div>

in the MWE below, “start” is never displayed. is there a way to make it so?

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

```

---

<div class="post-metadata">

**Author:** ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)\
**Post date:** [November 22, 2024, 7:33pm UTC](https://discourse.julialang.org/t/updating-label-value-twice-in-the-same-makie-event-handler/122918/2 "2024-11-22T19:33:06Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)\
**Post date:** [November 24, 2024, 1:55pm UTC](https://discourse.julialang.org/t/updating-label-value-twice-in-the-same-makie-event-handler/122918/3 "2024-11-24T13:55:06Z")

</div>

thanks! and in my case at least `Threads.@spawn` instead throws a seg fault, perhaps because i switch Makie backends in the task.

---

<div class="post-metadata">

**Author:** ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)\
**Post date:** [November 24, 2024, 3:04pm UTC](https://discourse.julialang.org/t/updating-label-value-twice-in-the-same-makie-event-handler/122918/4 "2024-11-24T15:04:13Z")

</div>

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.
