Beispiel #1
0
    def _retrieve_data_in_trunk(self, indices, trunk=None):
        if trunk is None:
            trunk = self._get_batch_size()

        grouped_indices = self._regroup(indices, trunk)

        lock = threading.Lock()
        self.stock_info = None

        def update_each_group(group):
            info = self.latest(group)
            lock.acquire()
            if self.stock_info is None:
                self.stock_info = info
            else:
                self.stock_info = self.stock_info.append(info)
            lock.release()

        multi_thread(update_each_group, grouped_indices)
        return self.stock_info
 def test_multi_thread(self):
     triple = partial(operator.mul, 3)
     result = multi_thread(triple, [2, 5, 7])
     assert_that(result, equal_to([6, 15, 21]))
 def test_multi_thread_callback(self):
     double = partial(operator.mul, 2)
     result = multi_thread(int, ['3', '5', '9'], double, 3)
     assert_that(result, equal_to([6, 10, 18]))