[Python-bugs-list] [ python-Bugs-535495 ] threading.RLock memory leak

noreply@sourceforge.net noreply@sourceforge.net
Tue, 26 Mar 2002 17:41:32 -0800


Bugs item #535495, was opened at 2002-03-26 19:25
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=535495&group_id=5470

Category: Threads
>Group: Not a Bug
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Shane Green (shanegreen)
>Assigned to: Tim Peters (tim_one)
Summary: threading.RLock memory leak

Initial Comment:
each time a new thread acquires an rlock for the first
time it seems a Condition and a Dummy thread are
allocated to it.  If that thread then dies, the
condition and dummy are never cleaned up.  The code
snipit below will leave 100 instances of Condition and
DummyThread in memory.




import threading
import thread

_lock = threading.RLock()
def run():
  _lock.acquire()
  _lock.release()

for x in range(0, 100):
  thread.start_new_thread(run, ())

----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2002-03-26 20:41

Message:
Logged In: YES 
user_id=31435

True, but not a bug.  As the comment block in threading.py 
says,

# Dummy thread class to represent threads not started here.
# These aren't garbage collected when they die,
# nor can they be waited for.

Because threading didn't create these threads, it's 
impossible for threading to know when these threads die.  
As the docs for threading.Thread say, "They are never 
deleted, since it is impossible to detect the termination 
of alien threads."

If you don't want to leak thread structures, don't mix 
thread models:  use the threading module (instead of the 
thread module) to create your threads.  threading.py knows 
when the threads it creates dies, and cleans up after them 
properly.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=535495&group_id=5470