예제 #1
0
    def test_pool_unbound_fail(self):
        pool = ThreadPool(4)

        self.assertEqual(4, pool.poolSize())
        pool.addTask(ThreadPoolTest.numberer, 0, {})

        pool.nonBlockingStart()
        pool.join()

        self.assertTrue(pool.hasFailedTasks())
예제 #2
0
    def test_fill_pool(self):
        pool = ThreadPool(4)

        for index in range(10):
            pool.addTask(self.sleepTask, 2)

        pool.nonBlockingStart()
        time.sleep(0.5)
        self.assertEqual(pool.doneCount(), 0)
        self.assertEqual(pool.runningCount(), 4)

        pool.join()
예제 #3
0
    def load(self, fs, report_step, input_mask=None):
        """
         @type fs: EnkfFs
         @type report_step: int
         @type input_mask: BoolVector
         @rtype: PlotBlockData
        """

        state_map = fs.getStateMap()
        ensemble_size = len(state_map)

        if not input_mask is None:
            mask = BoolVector.copy(input_mask)
        else:
            mask = BoolVector(False, ensemble_size)

        state_map.selectMatching(mask, RealizationStateEnum.STATE_HAS_DATA)

        depth = self.getDepthValues(report_step)

        self.__permutation_vector = depth.permutationSort()
        depth.permute(self.__permutation_vector)

        plot_block_data = PlotBlockData(depth)

        thread_pool = ThreadPool()
        for index in range(ensemble_size):
            if mask[index]:
                thread_pool.addTask(self.loadVector, plot_block_data, fs,
                                    report_step, index)

        thread_pool.nonBlockingStart()
        thread_pool.join()

        return plot_block_data
예제 #4
0
    def test_pool_execution(self):
        pool = ThreadPool(4)

        result = {}
        for index in range(10):
            pool.addTask(self.numberer, index, result=result)

        pool.nonBlockingStart()
        pool.join()

        for index in range(10):
            self.assertTrue(index in result)
            self.assertTrue(result[index])

        self.assertFalse(pool.hasFailedTasks())
예제 #5
0
    def test_pool_creation(self):
        pool = ThreadPool(4)

        self.assertEqual(4, pool.poolSize())

        def noop(*args, **kwargs):
            pass

        pool.addTask(noop)
        self.assertEqual(1, pool.taskCount())

        pool.addTask(noop, 1, 2, 3)
        self.assertEqual(2, pool.taskCount())

        pool.addTask(noop,
                     1,
                     2,
                     3,
                     name="name",
                     group="group",
                     purpose="porpoise")
        self.assertEqual(3, pool.taskCount())

        self.assertEqual(pool.runningCount(), 0)
        self.assertEqual(pool.doneCount(), 0)