# Run a traced script in a loop leaks threads

**URL:** https://discourse.paraview.org/t/run-a-traced-script-in-a-loop-leaks-threads/4505
**Category:** ParaView Support
**Created:** [June 4, 2020, 12:24pm UTC](https://discourse.paraview.org/t/run-a-traced-script-in-a-loop-leaks-threads/4505 "2020-06-04T12:24:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![reox](https://discourse.paraview.org/user_avatar/discourse.paraview.org/reox/32/16237_2.png) [@reox](https://discourse.paraview.org/u/reox)
#### Post date: [June 4, 2020, 12:24pm UTC](https://discourse.paraview.org/t/run-a-traced-script-in-a-loop-leaks-threads/4505/1 "2020-06-04T12:24:24Z")

</div>

I have traced a short script which creates four views and renders them into a png.  
Now, I changed that to run in a loop for many input files. However, I see that the number of threads is rising after each run - which eventually leads to a situation where I can not fork new threads.

I have the following code after each loop run:

```
ResetSession()
Disconnect()
Connect()

```

While the rendering windows are closed, the threads are not.  
Do I need to remove any other objects somewhere to terminate the open threads?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 5, 2020, 3:06am UTC](https://discourse.paraview.org/t/run-a-traced-script-in-a-loop-leaks-threads/4505/2 "2020-06-05T03:06:27Z")

</div>

Do you have an simple example to reproduce this ?

---

<div class="post-metadata">

### Author: ![reox](https://discourse.paraview.org/user_avatar/discourse.paraview.org/reox/32/16237_2.png) [@reox](https://discourse.paraview.org/u/reox)
#### Post date: [June 5, 2020, 5:49am UTC](https://discourse.paraview.org/t/run-a-traced-script-in-a-loop-leaks-threads/4505/3 "2020-06-05T05:49:01Z")

</div>

So one thing first: while testing it, I found out that this problem seems to be in 5.6 only.  
I also tested now with 5.7, where there is a constant number of threads open at the same time.  
I’m now using 5.8-headless, which works also flawlessly. I could not get 5.7 to run on the machine I’m using…

Regardless, the script is attached.  
[mwe.py](https://discourse.paraview.org/uploads/short-url/2IPu1H8sbPYkY0MET7m8cy53Mmk.py) (6.5 KB)
