# Trying to kill a task from outside the task, can't find a kill() method

**URL:** <https://discourse.julialang.org/t/trying-to-kill-a-task-from-outside-the-task-cant-find-a-kill-method/100746>\
**Category:** New to Julia\
**Created:** [June 23, 2023, 3:46pm UTC](https://discourse.julialang.org/t/trying-to-kill-a-task-from-outside-the-task-cant-find-a-kill-method/100746 "2023-06-23T15:46:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![schaefer0](https://avatars.discourse-cdn.com/v4/letter/s/c6cbf5/32.png) [@schaefer0](https://discourse.julialang.org/u/schaefer0)\
**Post date:** [June 23, 2023, 3:46pm UTC](https://discourse.julialang.org/t/trying-to-kill-a-task-from-outside-the-task-cant-find-a-kill-method/100746/1 "2023-06-23T15:46:46Z")

</div>

Hi,  
is there a way to kill a task from outside the task?

I’m only guessing that this is a task thing and not a NATS thing, and  
there seems to be no kill() method, but if kill() only doesn’t work for NATS  
then I’ll reissue the question on the NATS github  
thank you in advance,

using NATS

sub = NATS.subscribe(nc, subject)

sub\_task = @async for msg in sub

```
println("msg="," ",msg)

```

end

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [June 23, 2023, 3:59pm UTC](https://discourse.julialang.org/t/trying-to-kill-a-task-from-outside-the-task-cant-find-a-kill-method/100746/2 "2023-06-23T15:59:09Z")

</div>

I think that killing `Task`s isn’t proper. I suppose you should rather communicate to the `Task` that it should exit using a `Channel`, or otherwise synchronize using, for example, `Semaphore`s.

Furthermore, I think you’re a bit confused about what `Task`s are/do, they’re just coroutines: [Tasks · The Julia Language](https://docs.julialang.org/en/v1/base/parallel/)

So they don’t run in parallel. Maybe you want threads or processes instead of `Task`s.
