Jim Baker avatar Jim Baker committed 9ad4f34

Fixed http://bugs.jython.org/issue2060 by adding threading.Thread.ident.

Comments (0)

Files changed (3)

Lib/test/test_threading.py

 
     # 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).
         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:
         _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):
         else:
             self._thread.join()
 
+    def ident(self):
+        return self._thread.getId()
+
+    ident = property(ident)
+
     def getName(self):
         return self._thread.getName()
 

src/org/python/modules/thread/thread.java

     }
 
     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:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.