|
From: <otm...@us...> - 2009-05-20 05:45:11
|
Revision: 6358
http://jython.svn.sourceforge.net/jython/?rev=6358&view=rev
Author: otmarhumbel
Date: 2009-05-20 05:44:58 +0000 (Wed, 20 May 2009)
Log Message:
-----------
on termination, delete the thread from the global _threads list
fixes issue #1348
Modified Paths:
--------------
trunk/jython/Lib/test/test_threading_jy.py
trunk/jython/Lib/threading.py
Modified: trunk/jython/Lib/test/test_threading_jy.py
===================================================================
--- trunk/jython/Lib/test/test_threading_jy.py 2009-05-18 21:52:55 UTC (rev 6357)
+++ trunk/jython/Lib/test/test_threading_jy.py 2009-05-20 05:44:58 UTC (rev 6358)
@@ -4,6 +4,9 @@
"""
import unittest
from test import test_support
+import threading
+import time
+import random
from threading import Thread
class ThreadingTestCase(unittest.TestCase):
@@ -13,8 +16,26 @@
self.assertEqual(t.getName(), '1')
t.setName(2)
self.assertEqual(t.getName(), '2')
+
+ # make sure activeCount() gets decremented (see issue 1348)
+ def test_activeCount(self):
+ activeBefore = threading.activeCount()
+ activeCount = 10
+ for i in range(activeCount):
+ t = Thread(target=self._sleep, args=(i,))
+ t.setDaemon(0)
+ t.start()
+ polls = activeCount
+ while activeCount > activeBefore and polls > 0:
+ time.sleep(1)
+ activeCount = threading.activeCount()
+ polls -= 1
+ self.assertTrue(activeCount <= activeBefore, 'activeCount should to be <= %s, instead of %s' % (activeBefore, activeCount))
+ def _sleep(self, n):
+ time.sleep(random.random())
+
def test_main():
test_support.run_unittest(ThreadingTestCase)
Modified: trunk/jython/Lib/threading.py
===================================================================
--- trunk/jython/Lib/threading.py 2009-05-18 21:52:55 UTC (rev 6357)
+++ trunk/jython/Lib/threading.py 2009-05-20 05:44:58 UTC (rev 6358)
@@ -294,7 +294,7 @@
pass
def __delete(self):
- pass
+ del _threads[self._thread.getId()]
class _MainThread(Thread):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|