# Using Makie with Threads.@spawn

**URL:** <https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618>\
**Category:** New to Julia\
**Tags:** task, threads, makie, glmakie\
**Created:** [February 4, 2021, 1:20pm UTC](https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618 "2021-02-04T13:20:17Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)\
**Post date:** [February 4, 2021, 1:20pm UTC](https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618/1 "2021-02-04T13:20:17Z")

</div>

I’d like to plot a stream of data in a separate thread. Using Makie works up to a point, but the axis labels seem to come out wrong and it occasionally crashes. I don’t know if I’m doing something wrong or if it’s a limitation of Makie. I’ve had several problems with Makie recently (colorlegend() seems to have disappeared and lines!() and xlabel!() seem to break) so I’m wondering if there’s something wrong with my installation. Reinstalling Julia entirely didn’t help. I’m using VSCode on Windows 10. Any help would be gratefully received.

For example

```julia
Threads.@spawn begin
    h = Makie.lines(1:10:100, rand(10))
    display(h)
end

```

results in

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/7/d7623265ab99dac14b2bef5691b8592b845d164a.png)

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [February 4, 2021, 6:22pm UTC](https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618/2 "2021-02-04T18:22:42Z")

</div>

GLMakie isn’t thread safe. There is an open issue about it!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [February 4, 2021, 6:32pm UTC](https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618/3 "2021-02-04T18:32:00Z")

</div>

And colorlegend is replaced by the superior Colorbar, I recommend you check out the recent docs, a lot changed in the last weeks

---

<div class="post-metadata">

**Author:** ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)\
**Post date:** [February 4, 2021, 7:31pm UTC](https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618/4 "2021-02-04T19:31:54Z")

</div>

Thanks for the replies. I thought it might be thread safe enough if I only used it in a single thread but there’s probably a lot going on I don’t understand. At least it updates plots fast enough to keep up with my data stream so I’ll carry on using it and hope full thread safety comes eventually.

I’ll try out Colorbar and take another look at the docs - thanks.

---

<div class="post-metadata">

**Author:** ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)\
**Post date:** [May 19, 2021, 1:39pm UTC](https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618/5 "2021-05-19T13:39:50Z")

</div>

This seems to be working after this morning’s update and labels the axes correctly. ]status shows GLMakie as v0.2.7.

The plot window’s rather small by default (I have a 4k screen) but never mind.

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [January 20, 2022, 1:19pm UTC](https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618/6 "2022-01-20T13:19:40Z")

</div>

> [@sdanisch](#):
>
> GLMakie isn’t thread safe. There is an open issue about it!

Can you point to the issue?  
Also, is CairoMakie thread safe?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [January 20, 2022, 1:42pm UTC](https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618/7 "2022-01-20T13:42:12Z")

</div>

No it’s not, fonts will probably cause trouble.

---

<div class="post-metadata">

**Author:** ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)\
**Post date:** [January 20, 2022, 1:56pm UTC](https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618/8 "2022-01-20T13:56:44Z")

</div>

For what it’s worth, I’ve been using GLMakie with ThreadPools and it’s been working fine. Maybe I’ve just been lucky.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [January 20, 2022, 2:04pm UTC](https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618/9 "2022-01-20T14:04:48Z")

</div>

I guess one can get lucky, but it’s definitely not designed with thread-safety in mind. FreeType for example is generally not threadsafe if I remember correctly.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [January 20, 2022, 2:52pm UTC](https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618/10 "2022-01-20T14:52:26Z")

</div>

Ha, can you post an example?

---

<div class="post-metadata">

**Author:** ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)\
**Post date:** [January 20, 2022, 4:37pm UTC](https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618/11 "2022-01-20T16:37:58Z")

</div>

Sorry, it’s a while since I wrote that bit of our system and I misremembered what I’d done. I think GLMakie does indeed cause Julia to crash if you call it from more than one thread but it seems to be OK in a multi-threaded situation if all the calls are in only one of the threads. In my case I put all the GLMakie calls in thread 2 and feed it with data from thread 3 via a Channel.

As described in my original post that used to cause problems with the axis labels but it seems OK now.

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [January 23, 2022, 1:51pm UTC](https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618/12 "2022-01-23T13:51:53Z")

</div>

[https://github.com/JuliaPlots/Makie.jl/issues/812](https://github.com/JuliaPlots/Makie.jl/issues/812)

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [January 23, 2022, 2:00pm UTC](https://discourse.julialang.org/t/using-makie-with-threads-spawn/54618/13 "2022-01-23T14:00:38Z")

</div>

Ah cool… Yeah that could work! I was never sure if it does, so nice to see it actually works!
