# Threads.@spawn can not run many time?

**URL:** https://discourse.julialang.org/t/threads-spawn-can-not-run-many-time/71765
**Category:** New to Julia
**Tags:** question, task
**Created:** [November 19, 2021, 8:38am UTC](https://discourse.julialang.org/t/threads-spawn-can-not-run-many-time/71765 "2021-11-19T08:38:25Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![HANHAOHAN](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hanhaohan/32/36366_2.png) [@HANHAOHAN](https://discourse.julialang.org/u/HANHAOHAN)
#### Post date: [November 19, 2021, 8:38am UTC](https://discourse.julialang.org/t/threads-spawn-can-not-run-many-time/71765/1 "2021-11-19T08:38:25Z")

</div>

HELP!!!  
code as following:

```nohighlight
cmid = Channel(100)
while true
    wait(cmid)
    (mid::UInt32, video_name::String) = take!(cmid)
    append!(mid_list, fetch_from_list!(tasklist))
    t = Threads.@spawn get_frmkb(mid, video_name)
    @show t
    push!(tasklist, t);
    @show(typeof(tasklist[1]))
end

```

after running a while, about fetched 130 from cmid, may output `@show t` `@show(typeof(tasklist[1]))` many times continuously.  
Why the code `wait(cmid)` does not remain blocked?  
What a horror!

error output as follows:  
`Base.IOError("could not spawn `/root/.julia/artifacts/d90964dba054653e9757ab4167194a12fe864117/bin/ffprobe -v error -select\_streams v:0 -show\_entries stream=nb\_frames -of default=nokey=1:noprint\_wrappers=1 2c50300b2305dc9a0fdf35b732912047.mp4`: argument list too long (E2BIG)", -7)`

---

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [November 19, 2021, 7:53pm UTC](https://discourse.julialang.org/t/threads-spawn-can-not-run-many-time/71765/2 "2021-11-19T19:53:08Z")

</div>

I can not reproduce the behaviour. When I run your script it seems to wait for something?

---

<div class="post-metadata">

### Author: ![HANHAOHAN](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hanhaohan/32/36366_2.png) [@HANHAOHAN](https://discourse.julialang.org/u/HANHAOHAN)
#### Post date: [November 20, 2021, 12:56am UTC](https://discourse.julialang.org/t/threads-spawn-can-not-run-many-time/71765/3 "2021-11-20T00:56:16Z")

</div>

I have made some new progress.  
1, after limiting the number of spwan threads less than Threads.nthreads() will reduce the probability of error, for example, nthreads()=8 when limiting the number of threads out of spwan to 5 when almost no error.  
2, the program spwan threads inside the implementation of the function, call the library also calls spwan

---

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [November 20, 2021, 1:01am UTC](https://discourse.julialang.org/t/threads-spawn-can-not-run-many-time/71765/4 "2021-11-20T01:01:33Z")

</div>

Still I don’t see a way how to reproduce your problem?

---

<div class="post-metadata">

### Author: ![HANHAOHAN](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hanhaohan/32/36366_2.png) [@HANHAOHAN](https://discourse.julialang.org/u/HANHAOHAN)
#### Post date: [November 20, 2021, 1:42am UTC](https://discourse.julialang.org/t/threads-spawn-can-not-run-many-time/71765/5 "2021-11-20T01:42:14Z")

</div>

There may be another problem as main cause:  
`download(url, path)` provide not complete file to the new thread which lead to the Error `ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 2c50300b2305dc9a0fdf35b732912047.mp4`.  
Above is reproduced use the videos which can not open with VLM. But the size equal to the complete video which could be played.

And how to guarantee the file downloaded with `download` be complete?

---

<div class="post-metadata">

### Author: ![HANHAOHAN](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hanhaohan/32/36366_2.png) [@HANHAOHAN](https://discourse.julialang.org/u/HANHAOHAN)
#### Post date: [January 12, 2022, 6:36am UTC](https://discourse.julialang.org/t/threads-spawn-can-not-run-many-time/71765/6 "2022-01-12T06:36:24Z")

</div>

This error proved to be error in package VideoIO. After call get\_number\_frames some times, the error will be reproduced.
