List of running live_loops

Is it somehow possible to get a list of live_loop names that are running when the code is run again? Or test if certain named live_loop is still running?

I am trying to create some code that would reset shared variables if certain live_loops have been stopped.

I managed to get a list of thread names:

live_loop :foo, seed: 2 do
  sleep 1
end

live_loop :bar, seed: 2 do
  sleep 1
end

live_loop :baz, seed: 2 do
  stop
  sleep 1
end

Thread.list.each do |t|
  sonic_thread = t.thread_variable_get(:sonic_pi_system_thread_locals)
  if sonic_thread then
    named_thread = sonic_thread.get(:sonic_pi_local_spider_users_thread_name)
    if named_thread then
      print named_thread
    end
  end
end

This doesnt know if the live_loop is stopped or not … but kind of works for me. However, it would be nice if there were some helpers like:

a = list_live_loops
b = list_running_live_loops
c = list_stopped_live_loops

print "foo is stopped" if is_stopped :foo
1 Like