diff --git a/src/AstroSimBase.jl b/src/AstroSimBase.jl index 49f1c83..398bde1 100644 --- a/src/AstroSimBase.jl +++ b/src/AstroSimBase.jl @@ -73,11 +73,18 @@ end function need_to_interrupt(OutputDir::String) If there is a file named `stop` in folder `OutputDir`, return true; else, return `false`. + +## Keywords +- `remove`: if true, remove the `stop` file asynchronously +- `delay`: if true, wait for 0.1 second to avoid file locking error """ -function need_to_interrupt(OutputDir::String; remove = false) +function need_to_interrupt(OutputDir::String; remove = false, delay = true) if isfile(joinpath(OutputDir, "stop")) if remove - rm(joinpath(OutputDir, "stop"), force = true) + Threads.@spawn begin + delay && sleep(0.1) + rm(joinpath(OutputDir, "stop"), force = true) + end end return true else diff --git a/test/runtests.jl b/test/runtests.jl index d96d1ee..411f676 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -39,5 +39,8 @@ end interrupt("output") @test need_to_interrupt("output") @test need_to_interrupt("output", remove = true) + + @test isfile("output/stop") + sleep(0.2) @test !isfile("output/stop") end