# Stop/terminate a (sub)task started with @async

**URL:** <https://discourse.julialang.org/t/stop-terminate-a-sub-task-started-with-async/32193>\
**Category:** General Usage\
**Tags:** question, task\
**Created:** [December 12, 2019, 12:29pm UTC](https://discourse.julialang.org/t/stop-terminate-a-sub-task-started-with-async/32193 "2019-12-12T12:29:07Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![attdona](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/attdona/32/15859_2.png) [@attdona](https://discourse.julialang.org/u/attdona)\
**Post date:** [September 14, 2022, 2:51pm UTC](https://discourse.julialang.org/t/stop-terminate-a-sub-task-started-with-async/32193/16 "2022-09-14T14:51:44Z")

</div>

This is not a julia 1.8 problem but instead an issue with the package `BetterFileWatching.jl`.

The culprit is the line:

```julia
try wait(watch_task) catch; end

```

at [BetterFileWatching.jl/BetterFileWatching.jl at main · JuliaPluto/BetterFileWatching.jl · GitHub](https://github.com/JuliaPluto/BetterFileWatching.jl/blob/main/src/BetterFileWatching.jl#L123:)

When you schedule an `InterruptException()` you silently interrupt the `wait` of the `watch_task` async task but not the `watch_task` task that outlives `watch_folder`.

This is a simplified version that shows the same issue:

```julia
function watch_task()
    while true
        @info "doing something ..."
        sleep(3)
    end
    
end

function watch_folder()
    t = @async watch_task()
    try wait(t) catch; end
end

task = @async watch_folder()

sleep(5)

schedule(task, InterruptException(), error=true)

```

Eventually consider to open a `BetterFileWatchingIssue.jl` github issue …

Greetings, Attilio

---

_[View the full topic](https://discourse.julialang.org/t/stop-terminate-a-sub-task-started-with-async/32193)._
