Commits

Lenard Lindstrom committed 7cec8bc

Make pygame.threads Python 3.x compatible, as per issue #146

  • Participants
  • Parent commits ae2160c

Comments (0)

Files changed (3)

File lib/threads/__init__.py

 from pygame.compat import geterror
 
 if sys.version_info[0] == 3:
-    from multiprocessing import JoinableQueue as Queue
+    from queue import Queue
     from queue import Empty
 elif (sys.version_info[0] == 2 and sys.version_info[1] < 5):
     from Py25Queue import Queue
         # TODO: the traceback doesn't show up nicely.
         # NOTE: TODO: we might want to return the results anyway?  This should be an option.
         if stop_on_error:
-            error_ones = filter(lambda x:x.exception, results)
+            error_ones = list(filter(lambda x:x.exception, results))
             if error_ones:
                 raise error_ones[0].exception
         

File test/threads_tags.py

-__tags__ = []
-
-import sys
-if sys.version_info >= (3, 0, 0):
-    __tags__.extend(('ignore', 'subprocess_ignore'))
-

File test/threads_test.py

     from test.test_utils import test_not_implemented, unittest
 from pygame.threads import FuncResult, tmap, WorkerQueue, Empty, STOP
 from pygame import threads
+from pygame.compat import xrange_
 
 import time
 
         wq.stop()
 
         self.assert_(fr.result  == 2)
-        self.assert_(fr2.result == 3)
+        self.assertEqual(fr2.result, 3)
 
     def test_do(self):
 
         self.assert_(len(wq.pool) > 0)
         for t in wq.pool: self.assert_(t.isAlive())
         
-        for i in xrange(200): wq.do(lambda x: x+1, i)
+        for i in xrange_(200): wq.do(lambda x: x+1, i)
         
         wq.stop()
         for t in wq.pool: self.assert_(not t.isAlive())
 
         wq = WorkerQueue()
         
-        for i in xrange(2000): wq.do(lambda x: x+1, i)
+        for i in xrange_(2000): wq.do(lambda x: x+1, i)
         wq.wait()
 
         self.assertRaises(Empty, wq.queue.get_nowait)
           #        results, is returned as a list of FuncResult instances.
           # stop_on_error -
 
-        func, data = lambda x:x+1, xrange(100)
+        func, data = lambda x:x+1, xrange_(100)
 
-        tmapped = tmap(func, data)
-        mapped = map(func, data)
+        tmapped = list(tmap(func, data))
+        mapped = list(map(func, data))
 
-        self.assert_(tmapped == mapped)
+        self.assertEqual(tmapped, mapped)
         
     def test_tmap__None_func_and_multiple_sequences(self):
         return     #TODO
         wq, results = tmap(lambda x:x, r, num_workers = 5, wait=False)
         wq.wait()
         r2 = map(lambda x:x.result, results)
-        self.assert_(r == r2)
+        self.assertEqual(list(r), list(r2))
 
     def test_FuncResult(self):
         # as of 2008-06-28
         # Results are stored in result attribute
         fr = FuncResult(lambda x:x+1)
         fr(2)
-        self.assert_(fr.result == 3)
+        self.assertEqual(fr.result, 3)
         
         # Exceptions are store in exception attribute
         self.assert_(fr.exception is None,  "when no exception raised")