Package solvcon :: Package tests :: Module test_mthread
[hide private]
[frames] | no frames]

Source Code for Module solvcon.tests.test_mthread

 1  # -*- coding: UTF-8 -*- 
 2   
 3  from unittest import TestCase 
 4   
5 -class TestPool(TestCase):
6 - def work(self, istart, iend):
7 return iend-istart
8 - def test_run_multi_thread(self):
9 from ..mthread import ThreadPool 10 ncore = 4 11 tpool = ThreadPool(ncore) 12 iter_end = 1000 13 iter_start = -1000 14 incre = (iter_end-iter_start)/ncore + 1 15 args = list() 16 istart = iter_start 17 for it in range(ncore): 18 iend = min(istart+incre, iter_end) 19 args.append((istart, iend)) 20 istart = iend 21 ret = tpool(self.work, args) 22 self.assertEqual(sum(ret), iter_end-iter_start)
23