Using Makie with Threads.@spawn

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

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

results in

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

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

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.

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.

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

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

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

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.

Ha, can you post an example?

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.

https://github.com/JuliaPlots/Makie.jl/issues/812

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