Reputation: 13914
How to I close a Python thread in order to make sure that everything in memory within a thread is cleared from memory? Currently, I have a list of threads that I join in the following manner:
for t in threadlist:
t.join(5)
These threads were originally created looping over a list of arguments to pass to each thread with myfunc
which appends results to a list:
threadlist = []
for r in arglist:
t = Thread(target=myfunc, args=(r,))
t.daemon = True
threadlist.append(t)
When I look at what's in memory with pympler
all manner of things in the function called by the thread remain in memory after this executes. I need it to garbage collect as it would if I called myfunc
normally without threading.
Upvotes: 3
Views: 10195
Reputation: 15533
Resolved in comments:
The objects being deleted were contained within an object function.
Moving them outside of that object function and
into a regular function allowed garbage collecting to occur following delete.
Michael
Upvotes: 3