Library support parallel processing with multi-thread
Project description
Multi-thread Parallel Processing
Library support parallel processing with multi-thread.
Installation
$ pip3 install miltithread_parallel_processing
Example
Example job to calculate sum of the squares of the first billion natural numbers.
from multithread_processing.base_job import BaseJob
class SumSquaresJob(BaseJob):
def __init__(self, batch_size=1000, max_workers=4):
self.n = 10 ** 9
work_iterable = range(self.n)
super().__init__(work_iterable, batch_size, max_workers)
def _start(self):
self.sum = 0
def _execute(self):
self.batch_executor.execute(
self.work_iterable,
self._execute_batch,
total_items=self.n
)
def _execute_batch(self, works):
_sum = 0
for i in works:
_sum += i * i
self.sum += _sum
def _end(self):
print(f"Sum of the squares of the first {self.n} natural numbers: {self.sum}")
self.batch_executor.shutdown()
if __name__ == "__main__":
job = SumSquaresJob(
batch_size=10000,
max_workers=10
)
job.run()
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
Built Distribution
File details
Details for the file multithread_parallel_processing-1.0.0.tar.gz
.
File metadata
- Download URL: multithread_parallel_processing-1.0.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dbcad7b3fcb7a8120a118a90ce2934c503b4cf5fc964fb31dfeaf35625a721d |
|
MD5 | 204bfbebb2d16ed2b122d23681597e0c |
|
BLAKE2b-256 | 1614a3cd6e24f5c543f1bd00046208d497921826261b88d84e3c9fa644fe3f2f |
File details
Details for the file multithread_parallel_processing-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: multithread_parallel_processing-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f0cf3b722c2dd9bb69be0b588f7ea4e0887a4f6b5f695f67ea8c840d8959461 |
|
MD5 | 996466356dbde3d5d2b391094287edc3 |
|
BLAKE2b-256 | 91d40a775d145eec86a447a6d64465c13824887cd18d201f0fbe05bd0fc2effe |