I have an app that runs around 400 threads simultaneously. Everything works fine. And the user is able to stop the threads by pressing some button.
To stop a thread, I have implemented a global variable that is set as True
when the button is pressed. The threads checks for this variable regularly. If ON, return
.
return
works fine for me as a way of stopping the thread: I can see no more output to the user from the threads. However, when I check in the task manager memory I find the following:
Before starting the threads, Python takes up around 64MB RAM
After starting the threads, Python takes up around 700MB RAM
After stopping the threads as above, Python takes around 600MB RAM but it never goes back to 64MB RAM
I think this is a garbage collection problem. Maybe using return
is a bad idea. How can I solve this?
Update:
The App is a Tkinter App, and the threads runs in a separate TopLevel.