This library is used to enable batch processing by implementing python multiprocessing
Project description
batch_processor
install
pip install batch_processor
quickstart
from threading import Thread
from batch_processor import BatchProcessor
def batch_func(batch):
return [v + v for v in batch]
def create_bulk_request(n, processor):
print(n, processor.process(n))
processor = BatchProcessor(batch_func, worker_num=2, batch_size=32)
threads = []
for i in range(200):
t = Thread(target=create_bulk_request, args=(i, self.processor))
t.start()
threads.append(t)
for t in threads:
t.join()
This piece of code mimics 200 incomming requests that can be processed in batches whose size is 32. There are 2 workers. They take batches and double each integers in the batch, then return results in batches.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
batch_processor-0.0.1.tar.gz
(4.8 kB
view hashes)
Built Distribution
Close
Hashes for batch_processor-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7dd2da9ae6dcc13defc3d09391ba79e8b6ee0eba93f159ba7fd5fb00fed0c6bd |
|
MD5 | 4a9174cd5b3adc90970972e2f2345cb1 |
|
BLAKE2b-256 | 6338cd0b11371bb273e1e2612709c1f6795c5e5a3dfd1a676b5178a4486cd7dc |