From 89129fa7a64388865f03f787ea12bd09d5af276c Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Tue, 12 Sep 2023 20:13:24 +0200 Subject: [PATCH] Add __iNtErNaL_running_procs --- Project.toml | 2 +- src/Malt.jl | 7 +++++++ test/basic.jl | 2 ++ test/runtests.jl | 9 ++++++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 6f17fe5..4249244 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Malt" uuid = "36869731-bdee-424d-aa32-cab38c994e3b" authors = ["Sergio Alejandro Vargas "] -version = "1.0.0" +version = "1.0.1" [deps] Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" diff --git a/src/Malt.jl b/src/Malt.jl index f20157f..7b29d56 100644 --- a/src/Malt.jl +++ b/src/Malt.jl @@ -72,6 +72,9 @@ end Base.summary(io::IO, w::InProcessWorker) = write(io, "Malt.InProcessWorker in module $(w.host_module)") +const __iNtErNaL_running_procs = Set{Base.Process}() +__iNtErNaL_get_running_procs() = filter!(Base.process_running, __iNtErNaL_running_procs) + """ Malt.Worker() @@ -98,6 +101,10 @@ mutable struct Worker <: AbstractWorker # Spawn process cmd = _get_worker_cmd(; env, exeflags) proc = open(cmd, "w+") + + # Keep internal list + __iNtErNaL_get_running_procs() + push!(__iNtErNaL_running_procs, proc) # Block until reading the port number of the process (from its stdout) port_str = readline(proc) diff --git a/test/basic.jl b/test/basic.jl index b4b1fee..bc5a1a5 100644 --- a/test/basic.jl +++ b/test/basic.jl @@ -10,9 +10,11 @@ w = W() @test m.isrunning(w) === true + W === m.Worker && @test length(m.__iNtErNaL_get_running_procs()) == 1 # Terminating workers takes about 0.5s m.stop(w) @test m.isrunning(w) === false + W === m.Worker && @test length(m.__iNtErNaL_get_running_procs()) == 0 end diff --git a/test/runtests.jl b/test/runtests.jl index 68d7723..f445673 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,11 +1,18 @@ import Malt as m using Test + +v() = @assert isempty(m.__iNtErNaL_get_running_procs()) + +v() include("basic.jl") +v() include("exceptions.jl") +v() include("nesting.jl") +v() include("benchmark.jl") - +v() #TODO: