spacepaste

  1.  
  2. from multiprocessing.pool import ThreadPool
  3. import numpy as np
  4. def clean_index_list(obj):
  5. n = len(obj)
  6. converted = np.array(obj, dtype=object)
  7. floats = np.empty(n, dtype='f8')
  8. complexes = np.empty(n, dtype='c16')
  9. ints = np.empty(n, dtype='i8')
  10. uints = np.empty(n, dtype='u8')
  11. for i in xrange(n):
  12. val = converted[i]
  13. uints[i] = val
  14. return uints, 0
  15. n = 20000
  16. def run_test(*args):
  17. index = range(n)
  18. converted, all_arrays = clean_index_list(index)
  19. print("%3i %i" % args[0])
  20. return converted
  21. def test_multithread(i):
  22. pool = ThreadPool(10)
  23. results = pool.map(run_test, zip(range(200), [i]*200))
  24. for r in results:
  25. assert np.max(r) == n - 1,'max(r) is %d not %d' % (np.max(r), n - 1)
  26. if __name__ == '__main__':
  27. for i in range(10):
  28. test_multithread(i)
  29. print('ok')
  30.