# \#task

**URL:** https://discourse.julialang.org/tag/task/349.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [When could I need more threads than CPU cores, given 1.7+ task migration?](https://discourse.julialang.org/t/when-could-i-need-more-threads-than-cpu-cores-given-1-7-task-migration/137315)

<div class="topic-metadata">

**Author:** [@Benny](https://discourse.julialang.org/u/Benny)\
**Replies:** 16\
**Last updated:** [June 5, 2026, 2:36pm UTC](https://discourse.julialang.org/t/when-could-i-need-more-threads-than-cpu-cores-given-1-7-task-migration/137315 "2026-06-05T14:36:24Z")

</div>

Title basically says it all. To elaborate, the number of OS threads running in parallel is at most the number of virtual CPU cores. The reason for having many more threads is that some threads can or must idle, so there…

---

## [Type stability and tasks](https://discourse.julialang.org/t/type-stability-and-tasks/137136)

<div class="topic-metadata">

**Author:** [@moble](https://discourse.julialang.org/u/moble)\
**Replies:** 6\
**Last updated:** [May 16, 2026, 2:12pm UTC](https://discourse.julialang.org/t/type-stability-and-tasks/137136 "2026-05-16T14:12:14Z")

</div>

I’m looking into using tasks for some parallelization speedup, but I’m worried about type stability in the returned objects. For example, I’m calling a type-stable function over a range of Ints; the returned objects sho…

---

## [Does writing in parallel block the whole process?](https://discourse.julialang.org/t/does-writing-in-parallel-block-the-whole-process/134620)

<div class="topic-metadata">

**Author:** [@NonDairyNeutrino](https://discourse.julialang.org/u/NonDairyNeutrino)\
**Replies:** 4\
**Last updated:** [December 19, 2025, 8:37pm UTC](https://discourse.julialang.org/t/does-writing-in-parallel-block-the-whole-process/134620 "2025-12-19T20:37:43Z")

</div>

Say I have a large piece of data data that I want to write or serialize (for speed) to a file file with serialize("path/to/file", data). Done naively, this will block the rest of the program from executing. So it’s simp…

---

## [What is the correct way to use Base.OncePerThread?](https://discourse.julialang.org/t/what-is-the-correct-way-to-use-base-onceperthread/134597)

<div class="topic-metadata">

**Author:** [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Replies:** 7\
**Last updated:** [December 18, 2025, 4:52pm UTC](https://discourse.julialang.org/t/what-is-the-correct-way-to-use-base-onceperthread/134597 "2025-12-18T16:52:42Z")

</div>

I want to use Base.OncePerThread but it’s not clear what the intended usage is. Is the following a correct / safe / intended way to use Base.OncePerThread ? finalset = Set() tempsets = OncePerThread() do return Set…

---

## [How to coordinate shutting down tasks?](https://discourse.julialang.org/t/how-to-coordinate-shutting-down-tasks/134434)

<div class="topic-metadata">

**Author:** [@freeman](https://discourse.julialang.org/u/freeman)\
**Replies:** 8\
**Last updated:** [December 8, 2025, 4:20pm UTC](https://discourse.julialang.org/t/how-to-coordinate-shutting-down-tasks/134434 "2025-12-08T16:20:34Z")

</div>

I use tasks to decouple subscribing to data streams and publish downstream data streams. I also use Bool references to coordinate when all tasks should exit. Schematically, it looks like this: # main thread run\_flag = …

---

## [How many task can you create (related to wold age)?](https://discourse.julialang.org/t/how-many-task-can-you-create-related-to-wold-age/132807)

<div class="topic-metadata">

**Author:** [@Palli](https://discourse.julialang.org/u/Palli)\
**Replies:** 1\
**Last updated:** [October 1, 2025, 4:57pm UTC](https://discourse.julialang.org/t/how-many-task-can-you-create-related-to-wold-age/132807 "2025-10-01T16:57:41Z")

</div>

\[Possible should be in internals category?\] I see the world age is increased when I create tasks so I ask, and world age is an UInt i.e. 32-bit on 32-bit platforms. Certain language features capture the current task’s…

---

## [Why won't julia ERROR if a variable is not defined when scheduling?](https://discourse.julialang.org/t/why-wont-julia-error-if-a-variable-is-not-defined-when-scheduling/132438)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 22\
**Last updated:** [September 18, 2025, 7:01am UTC](https://discourse.julialang.org/t/why-wont-julia-error-if-a-variable-is-not-defined-when-scheduling/132438 "2025-09-18T07:01:22Z")

</div>

I’m very confused by this behavior: # start a new julia REPL julia\> function work(b) sleep(3) println(b) end; julia\> function main() t = Task(() -\> work(c)) schedule(t…

---

## [Timeout / early kill an external process](https://discourse.julialang.org/t/timeout-early-kill-an-external-process/53876)

<div class="topic-metadata">

**Author:** [@s-baumann](https://discourse.julialang.org/u/s-baumann)\
**Replies:** 3\
**Last updated:** [June 12, 2025, 10:27pm UTC](https://discourse.julialang.org/t/timeout-early-kill-an-external-process/53876 "2025-06-12T22:27:19Z")

</div>

I want to do a terminal command (on linux) with a timeout. I know there is not a timeout built into the run command so I was trying to do something to make one. So basically I tried: function run\_with\_timeout(command::S…

---

## [@info doesn't show whole vector in task](https://discourse.julialang.org/t/info-doesnt-show-whole-vector-in-task/128385)

<div class="topic-metadata">

**Author:** [@phma](https://discourse.julialang.org/u/phma)\
**Replies:** 0\
**Last updated:** [April 24, 2025, 7:53pm UTC](https://discourse.julialang.org/t/info-doesnt-show-whole-vector-in-task/128385 "2025-04-24T19:53:33Z")

</div>

I added this @info message to a function which is called from a task: @info "Blending" file=basename(blendFileName) streamNum blend=OffsetArrays.no\_offset\_view(blend) I get this output: ┌ Info: Blending │ file = "gg…

---

## [Bug in sleep() function - main thread work affecting sleep duration on running tasks](https://discourse.julialang.org/t/bug-in-sleep-function-main-thread-work-affecting-sleep-duration-on-running-tasks/101911)

<div class="topic-metadata">

**Author:** [@algunion](https://discourse.julialang.org/u/algunion)\
**Replies:** 47\
**Last updated:** [January 23, 2025, 8:36pm UTC](https://discourse.julialang.org/t/bug-in-sleep-function-main-thread-work-affecting-sleep-duration-on-running-tasks/101911 "2025-01-23T20:36:44Z")

</div>

What triggered the present experiment was my failure to find a reasonable solution for the issue raised by this topic. It turned out that the issue was unrelated to the HTTP.jl package and went deeper. Now, the experim…

---

## [Task termination](https://discourse.julialang.org/t/task-termination/25231)

<div class="topic-metadata">

**Author:** [@tomhaber](https://discourse.julialang.org/u/tomhaber)\
**Replies:** 7\
**Last updated:** [December 9, 2024, 1:53pm UTC](https://discourse.julialang.org/t/task-termination/25231 "2024-12-09T13:53:23Z")

</div>

I’m trying to get the following to work (or something like it) function execute(f::Function) exec = Executor() t = schedule(@task try while true run!(exec) yield() …

---

## [Communicating across worker processes](https://discourse.julialang.org/t/communicating-across-worker-processes/118017)

<div class="topic-metadata">

**Author:** [@ndehngwa](https://discourse.julialang.org/u/ndehngwa)\
**Replies:** 2\
**Last updated:** [August 12, 2024, 5:30am UTC](https://discourse.julialang.org/t/communicating-across-worker-processes/118017 "2024-08-12T05:30:45Z")

</div>

Hello. I just got into julia and i could use some help. I am trying to create an application that listens for instructions form the command line and sends them to a worker process. The worker process performs some compu…

---

## [Using Tasks 101](https://discourse.julialang.org/t/using-tasks-101/114878)

<div class="topic-metadata">

**Author:** [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Replies:** 15\
**Last updated:** [July 30, 2024, 7:49pm UTC](https://discourse.julialang.org/t/using-tasks-101/114878 "2024-07-30T19:49:31Z")

</div>

I’m not sure if this is the right place to post this, but I spent a lot of time learning about Tasks recently for a project at work, and wrote up a blog post tutorial summarizing how to use them: https://www.lesswrong.co…

---

## [How does io redirection work with tasks?](https://discourse.julialang.org/t/how-does-io-redirection-work-with-tasks/112405)

<div class="topic-metadata">

**Author:** [@jules](https://discourse.julialang.org/u/jules)\
**Replies:** 2\
**Last updated:** [April 2, 2024, 11:56pm UTC](https://discourse.julialang.org/t/how-does-io-redirection-work-with-tasks/112405 "2024-04-02T23:56:28Z")

</div>

I don’t understand this simple MWE: julia\> redirect\_stdio(;stdout = devnull) do @async println("hello") @async redirect\_io(; stdout = devnull) do println("hey") end …

---

## [Is there a way to abort a task that does not yield?](https://discourse.julialang.org/t/is-there-a-way-to-abort-a-task-that-does-not-yield/109468)

<div class="topic-metadata">

**Author:** [@taotree](https://discourse.julialang.org/u/taotree)\
**Replies:** 3\
**Last updated:** [January 31, 2024, 1:16pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-abort-a-task-that-does-not-yield/109468 "2024-01-31T13:16:03Z")

</div>

I searched for running a task with a timeout, but all the answers I found used async tasks which won’t work because the whole point is that the code doesn’t yield. I understand that killing a thread is generally bad, bu…

---

## [\[ANN\] PriorityChannels.jl](https://discourse.julialang.org/t/ann-prioritychannels-jl/19234)

<div class="topic-metadata">

**Author:** [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Replies:** 5\
**Last updated:** [September 17, 2023, 6:49pm UTC](https://discourse.julialang.org/t/ann-prioritychannels-jl/19234 "2023-09-17T18:49:04Z")

</div>

I’ve created a small package PriorityChannels.jl that implements a PriorityChannel that mimics Base.Channel , but where each element is associated with a priority. take! always returns the highest priority element. In…

---

## [Separating stderr based on task](https://discourse.julialang.org/t/separating-stderr-based-on-task/101841)

<div class="topic-metadata">

**Author:** [@tlienart](https://discourse.julialang.org/u/tlienart)\
**Replies:** 1\
**Last updated:** [July 21, 2023, 12:28pm UTC](https://discourse.julialang.org/t/separating-stderr-based-on-task/101841 "2023-07-21T12:28:04Z")

</div>

Say I have: a background task BT which may write to stderr a main task MT which may also write to stderr I care about stderr from (MT) but not from (BT) and would like to hide things that come from (BT) as they’re unr…

---

## [Interrupts in @async code](https://discourse.julialang.org/t/interrupts-in-async-code/95837)

<div class="topic-metadata">

**Author:** [@ettersi](https://discourse.julialang.org/u/ettersi)\
**Replies:** 20\
**Last updated:** [July 19, 2023, 4:16pm UTC](https://discourse.julialang.org/t/interrupts-in-async-code/95837 "2023-07-19T16:16:08Z")

</div>

I’m trying to wrap my head around how Julia handles interrupts in @async code. I have three different scripts that I’m trying to interrupt using ctrl+c, with various degrees of success. Script1: julia\> @async begin …

---

## [Interrupt \`Threads.@threads\` computation](https://discourse.julialang.org/t/interrupt-threads-threads-computation/71199)

<div class="topic-metadata">

**Author:** [@disberd](https://discourse.julialang.org/u/disberd)\
**Replies:** 14\
**Last updated:** [April 28, 2023, 12:39pm UTC](https://discourse.julialang.org/t/interrupt-threads-threads-computation/71199 "2023-04-28T12:39:01Z")

</div>

I sometime deal with very lengthy computation that I would like to interrupt before they finish. I can achieve this by wrapping the function with @async and then throw an InterruptException() to the task when I want it …

---

## [Help writing a timeout macro](https://discourse.julialang.org/t/help-writing-a-timeout-macro/16591)

<div class="topic-metadata">

**Author:** [@lstagner](https://discourse.julialang.org/u/lstagner)\
**Replies:** 12\
**Last updated:** [March 26, 2023, 12:32pm UTC](https://discourse.julialang.org/t/help-writing-a-timeout-macro/16591 "2023-03-26T12:32:16Z")

</div>

I have a function that can either execute quickly or take a very long time. I want to kill the function after a certain amount of time so I can fall back on a more reliable method. I should be able to do this using a mac…

---

## [Construct already completed task](https://discourse.julialang.org/t/construct-already-completed-task/95577)

<div class="topic-metadata">

**Author:** [@ettersi](https://discourse.julialang.org/u/ettersi)\
**Replies:** 0\
**Last updated:** [March 5, 2023, 3:03pm UTC](https://discourse.julialang.org/t/construct-already-completed-task/95577 "2023-03-05T15:03:35Z")

</div>

What’s the best way to construct a Task which has already completed? My current best shot is t = @async nothing wait(t) but this feels both clumsy and inefficient. The use case is that I would like to have a backgroun…

---

## [Where to set a timeout on a task](https://discourse.julialang.org/t/where-to-set-a-timeout-on-a-task/93579)

<div class="topic-metadata">

**Author:** [@1153dent](https://discourse.julialang.org/u/1153dent)\
**Replies:** 2\
**Last updated:** [January 28, 2023, 4:40pm UTC](https://discourse.julialang.org/t/where-to-set-a-timeout-on-a-task/93579 "2023-01-28T16:40:48Z")

</div>

hi there Has anyone got an effective approach to setting a timeout on multiple async calls. So if I send out 10 calls each with it’s own id and timer. I would handle the callback in a wrapper. Can I determine WHICH ti…

---

## [Relation of coroutines, threads, and Tasks](https://discourse.julialang.org/t/relation-of-coroutines-threads-and-tasks/87735)

<div class="topic-metadata">

**Author:** [@Ross\_Boylan](https://discourse.julialang.org/u/Ross_Boylan)\
**Replies:** 4\
**Last updated:** [October 1, 2022, 7:35am UTC](https://discourse.julialang.org/t/relation-of-coroutines-threads-and-tasks/87735 "2022-10-01T07:35:04Z")

</div>

A simple version of my question is “How can Tasks and Channels, which are coroutine-related, be used safely with threads?” The “how” here is more in these sense of “how is it possible” than “how do I code it”, since the…

---

## [Stop/terminate a (sub)task started with @async](https://discourse.julialang.org/t/stop-terminate-a-sub-task-started-with-async/32193)

<div class="topic-metadata">

**Author:** [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Replies:** 16\
**Last updated:** [September 15, 2022, 3:11pm UTC](https://discourse.julialang.org/t/stop-terminate-a-sub-task-started-with-async/32193 "2022-09-15T15:11:20Z")

</div>

Hello, I search a bit here and on the web and found out that obviously there is no “official” way to terminate a started task in julia yet. However, throw an Interruption error seems to work as a workaround for now. Bu…

---

## [Finishing a task](https://discourse.julialang.org/t/finishing-a-task/86784)

<div class="topic-metadata">

**Author:** [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Replies:** 5\
**Last updated:** [September 9, 2022, 2:41pm UTC](https://discourse.julialang.org/t/finishing-a-task/86784 "2022-09-09T14:41:13Z")

</div>

If I’m manipulating tasks with yieldto, without the scheduler, when a task finishes it just hangs the REPL (i.e. yieldto(@task 1+1) hangs). So I have to yieldto back to the main task at the end (or is there some other wa…

---

## [Any small example of a queue like system, where a function is automatically executed when a new item pops in the queue?](https://discourse.julialang.org/t/any-small-example-of-a-queue-like-system-where-a-function-is-automatically-executed-when-a-new-item-pops-in-the-queue/86616)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 12\
**Last updated:** [September 2, 2022, 8:31pm UTC](https://discourse.julialang.org/t/any-small-example-of-a-queue-like-system-where-a-function-is-automatically-executed-when-a-new-item-pops-in-the-queue/86616 "2022-09-02T20:31:38Z")

</div>

Hello! I have some Julia code which detects when new files are made in a folder. The name of these files are then passed to a vector. Whenever a new item enters the vector, I wish to have a function detect this and run …

---

## [Nested async and sync](https://discourse.julialang.org/t/nested-async-and-sync/86063)

<div class="topic-metadata">

**Author:** [@wuxinyu](https://discourse.julialang.org/u/wuxinyu)\
**Replies:** 1\
**Last updated:** [August 21, 2022, 5:17am UTC](https://discourse.julialang.org/t/nested-async-and-sync/86063 "2022-08-21T05:17:25Z")

</div>

I want to do multi Task (A,B) pairs which have no connections with each other. Each Task A include multi Task a. Task A has to be done before B start in the same one (A,B) pair. So it’s like @async for loop do multi (A,…

---

## [Is it possible to skip to the next loop on time limit?](https://discourse.julialang.org/t/is-it-possible-to-skip-to-the-next-loop-on-time-limit/84306)

<div class="topic-metadata">

**Author:** [@Funkerfish](https://discourse.julialang.org/u/Funkerfish)\
**Replies:** 6\
**Last updated:** [July 16, 2022, 7:55am UTC](https://discourse.julialang.org/t/is-it-possible-to-skip-to-the-next-loop-on-time-limit/84306 "2022-07-16T07:55:57Z")

</div>

Thanks to you guys I have learned the method to kill the loop on the time limit.https://discourse.julialang.org/t/how-would-i-stop-a-while-loop-after-n-amount-of-time/84299/2 but I am still wondering if there is any meth…

---

## [How to build a setInterval-like task?](https://discourse.julialang.org/t/how-to-build-a-setinterval-like-task/79595)

<div class="topic-metadata">

**Author:** [@Rratic](https://discourse.julialang.org/u/Rratic)\
**Replies:** 1\
**Last updated:** [April 17, 2022, 1:30pm UTC](https://discourse.julialang.org/t/how-to-build-a-setinterval-like-task/79595 "2022-04-17T13:30:09Z")

</div>

This is my idea task=@task begin while true sleep(1) foo() if should\_end # ? end end end But are there any simple ways to contact other than using global should\_end? how to end the task from inside the expression…

---

## [Task migration & data-race freedom](https://discourse.julialang.org/t/task-migration-data-race-freedom/78552)

<div class="topic-metadata">

**Author:** [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Replies:** 7\
**Last updated:** [March 28, 2022, 3:31am UTC](https://discourse.julialang.org/t/task-migration-data-race-freedom/78552 "2022-03-28T03:31:51Z")

</div>

In light of task migration, Tasks can now migrate among threads when they are re-scheduled. Previously, a Task would always run on whichever thread executed it first Can I still assume that f and g will never run con…

[Next page](https://discourse.julialang.org/tag/task/349.md?match_all_tags=true&page=1&tags%5B%5D=task)
