[ python-Bugs-1739118 ] Investigated ref leak report related to thread(regrtest.py -

SourceForge.net noreply at sourceforge.net
Tue Jun 19 03:13:32 CEST 2007


Bugs item #1739118, was opened at 2007-06-18 23:43
Message generated for change (Comment added) made by ocean-city
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1739118&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Threads
Group: Python 2.6
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Hirokazu Yamamoto (ocean-city)
Assigned to: Nobody/Anonymous (nobody)
Summary: Investigated ref leak report related to thread(regrtest.py -

Initial Comment:
Hello. I investigated ref leak report related to thread.
Please run python regrtest.py -R :: test_leak.py (attached file)
Sometimes ref leak is reported.
# I saw this as regression failure on python-checkins.

# total ref count 92578 -> 92669
  _Condition 2
  Thread 6
  _Event 1
  bool 10
  instancemethod 1
  code 2
  dict 9
  file 1
  frame 3
  function 2
  int 1
  list 2
  builtin_function_or_method 5
  NoneType 2
  str 27
  thread.lock 7
  tuple 5
  type 5

Probably this happens because threading.Thread is implemented as Python
code,
(expecially threading.Thread#join), the code of regrtest.py

        if i >= nwarmup:
            deltas.append(sys.gettotalrefcount() - rc - 2)

can run before thread really quits. (before Moudles/threadmodule.c
t_bootstrap()'s

 Py_DECREF(boot->func);
 Py_DECREF(boot->args);
 Py_XDECREF(boot->keyw);

runs)

So I experimentally inserted the code to wait for thread termination.
(attached file experimental.patch) And I confirmed error was gone.

# Sorry for hackish patch which only runs on windows. It should run
# on other platforms if you replace Sleep() in Python/sysmodule.c
# sys_debug_ref_leak_leave() with appropriate function.


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

>Comment By: Hirokazu Yamamoto (ocean-city)
Date: 2007-06-19 10:13

Message:
Logged In: YES 
user_id=1200846
Originator: YES

Umm, maybe still not enough? applied this patch (fix for 3 str leaks)
test_urllib2_localnet.py  still reports leaks sometimes.

Index: Lib/test/test_urllib2_localnet.py
===================================================================
--- Lib/test/test_urllib2_localnet.py	(revision 56002)
+++ Lib/test/test_urllib2_localnet.py	(working copy)
@@ -208,7 +208,7 @@
     testing.
     """
 
-    digest_auth_handler = DigestAuthHandler()
+    digest_auth_handler = None
 
     def log_message(self, format, *args):
         # Uncomment the next line for debugging.
@@ -240,6 +240,7 @@
     PROXY_URL = "http://127.0.0.1:%d" % PORT
 
     def setUp(self):
+        FakeProxyHandler.digest_auth_handler = DigestAuthHandler()
         FakeProxyHandler.digest_auth_handler.set_users({
             self.USER : self.PASSWD
             })
@@ -257,6 +258,7 @@
 
     def tearDown(self):
         self.server.stop()
+        FakeProxyHandler.digest_auth_handler = None
 
     def test_proxy_with_bad_password_raises_httperror(self):
         self._digest_auth_handler.add_password(self.REALM, self.URL,

///////////////////////////

test_urllib2_localnet leaked [2, 0, 0, 0] references, sum=2

# it is now rare case though....

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

Comment By: Hirokazu Yamamoto (ocean-city)
Date: 2007-06-19 02:48

Message:
Logged In: YES 
user_id=1200846
Originator: YES

Sorry, I updated the patch. Moved

fprintf(stderr, "================= thread leave\n");
current_thread_count--;

in threadmodule.c just before PyThread_exit_thread().
File Added: archive.zip

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

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


More information about the Python-bugs-list mailing list