Skip to content

Commit

Permalink
remove the stop file asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
islent committed Dec 26, 2023
1 parent 718aa15 commit d82d36e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/AstroSimBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d82d36e

Please sign in to comment.