[Jython-checkins] jython: Fixed http://bugs.jython.org/issue2060 by adding threading.Thread.ident.

jim.baker jython-checkins at python.org
Sat Jul 20 00:37:09 CEST 2013


http://hg.python.org/jython/rev/9ad4f341f030
changeset:   7112:9ad4f341f030
user:        Jim Baker <jim.baker at rackspace.com>
date:        Fri Jul 19 16:37:37 2013 -0600
summary:
  Fixed http://bugs.jython.org/issue2060 by adding threading.Thread.ident.

files:
  Lib/test/test_threading.py                |  5 ++---
  Lib/threading.py                          |  7 ++++++-
  src/org/python/modules/thread/thread.java |  3 +--
  3 files changed, 9 insertions(+), 6 deletions(-)


diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -71,7 +71,6 @@
 
     # Create a bunch of threads, let each do some work, wait until all are
     # done.
-    @unittest.skipIf(is_jython, "FIXME: not working on Jython")
     def test_various_ops(self):
         # This takes about n/3 seconds to run (about n/3 clumps of tasks,
         # times about 1 second per clump).
@@ -87,8 +86,8 @@
         for i in range(NUMTASKS):
             t = TestThread("<thread %d>"%i, self, sema, mutex, numrunning)
             threads.append(t)
-            self.assertEqual(t.ident, None)
-            self.assertTrue(re.match('<TestThread\(.*, initial\)>', repr(t)))
+            self.assertIsNotNone(t.ident)  # NOTE Java immediately assigns idents, unlike CPython
+            self.assertTrue(re.match('<TestThread\(.*, initial \d+\)>', repr(t)))
             t.start()
 
         if verbose:
diff --git a/Lib/threading.py b/Lib/threading.py
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -99,7 +99,7 @@
         _thread = self._thread
         status = ThreadStates[_thread.getState()]
         if _thread.isDaemon(): status + " daemon"
-        return "<%s(%s, %s)>" % (self.__class__.__name__, self.getName(), status)
+        return "<%s(%s, %s %s)>" % (self.__class__.__name__, self.getName(), status, self.ident)
 
     def __eq__(self, other):
         if isinstance(other, JavaThread):
@@ -125,6 +125,11 @@
         else:
             self._thread.join()
 
+    def ident(self):
+        return self._thread.getId()
+
+    ident = property(ident)
+
     def getName(self):
         return self._thread.getName()
 
diff --git a/src/org/python/modules/thread/thread.java b/src/org/python/modules/thread/thread.java
--- a/src/org/python/modules/thread/thread.java
+++ b/src/org/python/modules/thread/thread.java
@@ -90,10 +90,9 @@
     }
 
     public static long get_ident() {
-        return Py.java_obj_id(Thread.currentThread());
+        return Thread.currentThread().getId();
     }
     
-    
     public static long stack_size(PyObject[] args) {
         switch (args.length) {
             case 0:

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list