Beispiel #1
0
 def test_map_no_done(self):
     data = list(range(10))
     pool = fastthreadpool.Pool()
     pool.map(self.worker_cb, data, done_callback=False, unpack_args=False)
     pool.shutdown()
     assert not pool.done
     assert not pool.failed
Beispiel #2
0
 def test_map_gen_done(self):
     data = list(range(10))
     self.result = 0
     with fastthreadpool.Pool(done_callback=self.result_cb) as pool:
         pool.map(self.worker_gen_cb, data)
     assert not pool.done
     assert not pool.failed
     assert self.result == 45
Beispiel #3
0
 def test_map_gen_done_no_result(self):
     data = list(range(10))
     with fastthreadpool.Pool(done_callback=self.result_cb) as pool:
         pool.map(self.worker_gen_cb, data)
     assert not pool.done
     assert len(pool.failed) == len(data)
     assert pool.failed.popleft(
     ).args[0] == "'TestValues' object has no attribute 'result'"
Beispiel #4
0
 def test_map_gen(self):
     data = list(range(10))
     pool = fastthreadpool.Pool()
     pool.map(self.worker_gen_cb, data)
     pool.shutdown()
     assert not pool.failed
     assert len(pool.done) == len(data)
     assert sum(pool.done) == sum(data)
Beispiel #5
0
 def test_submit_gen_result_id(self):
     data = list(range(10))
     pool = fastthreadpool.Pool(result_id=True)
     for value in data:
         pool.submit(self.worker_gen_cb, value)
     pool.shutdown()
     assert not pool.failed
     assert len(pool.done) == 10
     assert sum([result[1] for result in pool.done]) == sum(data)
Beispiel #6
0
 def test_submit_gen(self):
     data = list(range(10))
     pool = fastthreadpool.Pool()
     for value in data:
         pool.submit(self.worker_gen_cb, value)
     pool.shutdown()
     assert not pool.failed
     assert len(pool.done) == 10
     assert sum(pool.done) == sum(data)
Beispiel #7
0
 def test_submit_pool_done(self):
     data = list(range(10))
     self.result = 0
     fastthreadpool.fastthreadpool.DBG.clear()
     with fastthreadpool.Pool(done_callback=self.result_cb) as pool:
         for value in data:
             pool.submit(self.worker_cb, value)
     assert not pool.failed
     assert len(pool.done) == 10
     assert sum(pool.done) == sum(data)
Beispiel #8
0
 def test_map_gen_failed(self):
     data = list(range(10))
     self.failed = []
     pool = fastthreadpool.Pool(failed_callback=self.failed_cb)
     pool.map(self.worker_gen_cb, data,
              unpack_args=True)  # Unpacking of int is not possible
     pool.shutdown()
     assert not pool.done
     assert not pool.failed
     assert len(self.failed) == len(data)
     assert self.failed[0].args[
         0] == "worker_gen_cb() argument after * must be an iterable, not int"
Beispiel #9
0
 def test_map_done(self):
     data = list(range(10))
     self.result = 0
     with fastthreadpool.Pool(done_callback=self.result_cb) as pool:
         pool.map(self.worker_cb, data)
     assert self.result == sum(data)
Beispiel #10
0
 def test_fastthreadpool_map(self):
     data = list(range(10))
     pool = fastthreadpool.Pool()
     pool.map(self.worker_cb, data, unpack_args=False)
     pool.shutdown()
     assert data == list(pool.done)
Beispiel #11
0
 def submit_done_cb(self, data):
     # Important: The result function is executed in the worker thread. So we need a
     #   lock in the result function!
     with fastthreadpool.Pool() as pool:
         for value in data:
             pool.submit_done(self.worker, self.locked_result_cb, value)
Beispiel #12
0
 def submit_pool_failed_cb(self, data):
     pool = fastthreadpool.Pool(failed_callback=self.failed_cb)
     for value in data:
         pool.submit(self.worker, value)
     pool.shutdown()
     self.result = sum(pool.done)
Beispiel #13
0
 def test_submit_gen_pool_done(self):
     data = list(range(10))
     with fastthreadpool.Pool(done_callback=self.result_cb) as pool:
         for value in data:
             pool.submit(self.worker_gen_cb, value)
     pass