Exemplo n.º 1
0
 def test_one_thread(self):
     th = threads.ThreadPool(self._workload, numthreads=1)
     th.queue_work(list(range(10)))
     th.wait()
     res = []
     while not self.results.empty():
         res.append(self.results.get())
     self.assertEqualNoOrder([0, 1, 4, 9, 16, 25, 36, 49, 64, 81], res)
Exemplo n.º 2
0
 def _threading(self, numthreads, count):
     th = threads.ThreadPool(self._workload, numthreads=numthreads)
     th.queue_work(list(range(count)))
     th.wait()
     res = []
     while not self.results.empty():
         res.append(self.results.get())
     self.assertEqualNoOrder([i * i for i in range(count)], res)
Exemplo n.º 3
0
 def test_threading_multi_queueing(self):
     th = threads.ThreadPool(self._workload, numthreads=5)
     th.queue_work(list(range(5)))
     th.queue_work(list(range(5, 10)))
     th.wait()
     res = []
     while not self.results.empty():
         res.append(self.results.get())
     self.assertEqualNoOrder([i * i for i in range(10)], res)
Exemplo n.º 4
0
 def test_starting(self):
     self.god.stub_class_method(threading.Thread, 'start')
     threading.Thread.start.expect_call().and_return(None)
     threading.Thread.start.expect_call().and_return(None)
     threading.Thread.start.expect_call().and_return(None)
     threading.Thread.start.expect_call().and_return(None)
     threading.Thread.start.expect_call().and_return(None)
     th = threads.ThreadPool(self._workload, numthreads=5)
     self.god.check_playback()