Commits

Frank Wierzbicki  committed 8049791 Merge

Merge 2.5.

  • Participants
  • Parent commits 652f4e9, 6dc91e6
  • Branches default

Comments (0)

Files changed (4)

File Lib/test/test_set_jy.py

 import unittest
 from test import test_support
 
+import threading
+
 if test_support.is_jython:
     from java.io import (ByteArrayInputStream, ByteArrayOutputStream,
                          ObjectInputStream, ObjectOutputStream)
         self.assertEqual(s & foo, 'rand')
         self.assertEqual(s ^ foo, 'rxor')
 
+    def test_pop_race(self):
+        # issue 1854
+        nthreads = 200
+        # the race might not happen the first time so we try a few just in case
+        for i in xrange(4):
+            s = set(range(200))
+            threads = [threading.Thread(target=s.pop) for i in range(nthreads)]
+            for t in threads: t.start()
+            for t in threads: t.join()
+            self.assertEqual(len(s), 0)
 
 class SetInJavaTestCase(unittest.TestCase):
 
         unserializer = ObjectInputStream(input)
         self.assertEqual(s, unserializer.readObject())
 
-
 def test_main():
     tests = [SetTestCase]
     if test_support.is_jython:

File Lib/test/test_zipimport_jy.py

File contents unchanged.
 
 Jython 2.5.3b2
   Bugs Fixed
+    - [ 1854 ] set().pop() race condition
     - [ 1730 ] functools.partial incorrectly makes __doc__ property readonly
     - [ 1537 ] expat: org.python.apache.xerces.parsers.SAXParser
     - [ 1268 ] SAX parsers wants to load external DTDs, causing an exception

File src/org/python/core/PySet.java

     }
 
     @ExposedMethod(doc = BuiltinDocs.set_pop_doc)
-    final PyObject set_pop() {
+    final synchronized PyObject set_pop() {
         Iterator iterator = _set.iterator();
         try {
             Object first = iterator.next();