Is there a way to get a list of all “live” tasks in the current session?
I’ve been looking into Julia’s task management code lately. I don’t have the full picture yet but I think this is hard beacuse there isn’t a master list of tasks.
Say I create a
Condition and a
Task that waits on it:
julia> c = Condition() julia> t = @async begin wait(c) println("finished waiting") end
When I run the
@async my new
Task is created and added to the
Workqueue (a queue of runnable tasks). When my current
Task needs to
wait for something (e.g. keyboard input at the REPL), it will pop off
t and switch to it. When
t runs it will call
wait(c), adding itself to
c's queue. At this point you could consider
t to be a “live” task, but it’s not stored in some global list, the only reference to it (aside from in our REPL session) is within
c's wait queue.
I think that to do this you’d need to do a full heap search starting at the GC roots (like a GC “mark” phase) and find all the
Task objects in
I’ve definitely thought it would be useful to have a
top-style list of active tasks (and ideally be able to kill them selectively), but that would probably require a step where all
Tasks register themselves with some global list on creation.