This is an archival dump of old wiki content --- see scipy.org for current material.
Please see http://scipy-cookbook.readthedocs.org/

Attachment 'test_handythread.py'

Download

   1 #!/usr/bin/env python
   2 import unittest
   3 
   4 import handythread
   5 
   6 
   7 class HandythreadTest(unittest.TestCase):
   8     def test_coverage(self):
   9         d = {}
  10         l = range(100)
  11         def f(x):
  12             d[x]=x**2
  13         handythread.foreach(f, l)
  14         for i in l:
  15             self.assertEqual(d[i],i**2)
  16 
  17     def test_return(self):
  18         l = range(100)
  19         r = handythread.foreach(lambda x: x**2, l, return_=True)
  20         for i in range(len(l)):
  21             self.assertEqual(l[i]**2,r[i])
  22 
  23     def test_return_1(self):
  24         l = range(100)
  25         r = handythread.foreach(lambda x: x**2, l, return_=True, threads=1)
  26         for i in range(len(l)):
  27             self.assertEqual(l[i]**2,r[i])
  28 
  29     def test_parallel_map(self):
  30         l = range(100)
  31         r = handythread.parallel_map(lambda x: x**2, l)
  32         for i in range(len(l)):
  33             self.assertEqual(l[i]**2,r[i])
  34 
  35 
  36 if __name__=='__main__':
  37     unittest.main()

New Attachment

File to upload
Rename to
Overwrite existing attachment of same name

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.