# Display progress in ThreadsX

**URL:** <https://discourse.julialang.org/t/display-progress-in-threadsx/70599>\
**Category:** General Usage\
**Tags:** question, multithreading\
**Created:** [October 29, 2021, 6:53am UTC](https://discourse.julialang.org/t/display-progress-in-threadsx/70599 "2021-10-29T06:53:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [October 29, 2021, 6:53am UTC](https://discourse.julialang.org/t/display-progress-in-threadsx/70599/1 "2021-10-29T06:53:24Z")

</div>

How can I display progress when using `ThreadsX`, with for example `ProgressMeter`?  
Silly MWE, but imagine `fun` was a relatively expensive function:

```julia
using ThreadsX
fun(x) = (sleep(1); sin(x))
x = rand(100)
y = ThreadsX.map(fun, x) # show the progress somehow

```

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [October 29, 2021, 8:15pm UTC](https://discourse.julialang.org/t/display-progress-in-threadsx/70599/2 "2021-10-29T20:15:41Z")

</div>

There’s [`Transducers.withprogress`](https://juliafolds.github.io/Transducers.jl/dev/reference/manual/#Transducers.withprogress) which can be used as `tcollect(withprogress(fun(a) for a in x); basesize = 1)` given that you have corresponding [https://github.com/JuliaLogging/ProgressLogging.jl](https://github.com/JuliaLogging/ProgressLogging.jl) monitors such as VS code and TerminalLoggers.jl.

Apparently I forgot to support `withprogress` in ThreadsX.jl. So you’d need to invoke Transducers.jl API directly ATM.

MWE:

```julia-repl
julia> using Logging, TerminalLoggers

julia> global_logger(TerminalLogger());

julia> using Transducers

julia> function fun(x)
           t0 = time_ns()
           while time_ns() - t0 < 1e8
           end
           sin(x)
       end
fun (generic function with 1 method)

julia> x = rand(300);

julia> y = tcollect(withprogress(fun(a) for a in x); basesize = 1)

```

That said, the responsiveness of `withprogress` in threaded execution is not very nice. Depending on the actual run-time of `fun`, it may work fine, though.
