]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 70897 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Tue, 31 Mar 2009 21:40:18 +0000 (21:40 +0000)
committerBenjamin Peterson <benjamin@python.org>
Tue, 31 Mar 2009 21:40:18 +0000 (21:40 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r70897 | benjamin.peterson | 2009-03-31 16:34:42 -0500 (Tue, 31 Mar 2009) | 1 line

  fix Thread.ident when it is the main thread or a dummy thread #5632
........

Lib/test/test_threading.py
Lib/threading.py
Misc/NEWS

index c8f9cac8f9c5f583833cc1b6bf4d8b37c3163c11..0057d0e8f8e074841f5ace4e2c362a6eb9d5cc1b 100644 (file)
@@ -83,11 +83,24 @@ class ThreadTests(unittest.TestCase):
             t.join(NUMTASKS)
             self.assert_(not t.is_alive())
             self.failIfEqual(t.ident, 0)
+            self.assertFalse(t.ident is None)
             self.assert_(re.match('<TestThread\(.*, \w+ -?\d+\)>', repr(t)))
         if verbose:
             print 'all tasks done'
         self.assertEqual(numrunning.get(), 0)
 
+    def test_ident_of_no_threading_threads(self):
+        # The ident still must work for the main thread and dummy threads.
+        self.assertFalse(threading.currentThread().ident is None)
+        def f():
+            ident.append(threading.currentThread().ident)
+            done.set()
+        done = threading.Event()
+        ident = []
+        thread.start_new_thread(f, ())
+        done.wait()
+        self.assertFalse(ident[0] is None)
+
     # run with a small(ish) thread stack size (256kB)
     def test_various_ops_small_stack(self):
         if verbose:
index a776c66752b0dfe74cd06a5611e0d1bd83ceafc7..c1791d7aef5ec2b243a321609a599d966d499d88 100644 (file)
@@ -500,9 +500,12 @@ class Thread(_Verbose):
                 return
             raise
 
+    def _set_ident(self):
+        self.__ident = _get_ident()
+
     def __bootstrap_inner(self):
         try:
-            self.__ident = _get_ident()
+            self._set_ident()
             self.__started.set()
             _active_limbo_lock.acquire()
             _active[self.__ident] = self
@@ -734,6 +737,7 @@ class _MainThread(Thread):
     def __init__(self):
         Thread.__init__(self, name="MainThread")
         self._Thread__started.set()
+        self._set_ident()
         _active_limbo_lock.acquire()
         _active[_get_ident()] = self
         _active_limbo_lock.release()
@@ -780,6 +784,7 @@ class _DummyThread(Thread):
         del self._Thread__block
 
         self._Thread__started.set()
+        self._set_ident()
         _active_limbo_lock.acquire()
         _active[_get_ident()] = self
         _active_limbo_lock.release()
index b3befb0f9fd9c156ee21eef69c20ff166ab26952..21268feab68c0dd306791f5c9ccd3b7cf6e4c8d5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -92,6 +92,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #5632: Thread.ident was None for the main thread and threads not created
+  with the threading module.
+
 - Issue #5400: Added patch for multiprocessing on netbsd compilation/support
 
 - Fix and properly document the multiprocessing module's logging