Metadata-Version: 2.1
Name: multithread-parallel-processing
Version: 0.1.0
Summary: Library support parallel processing with multi-thread
Home-page: https://github.com/hoangthanhlamm/multithread_parallel_processing
Author: VegetaIV
Author-email: hoangthanhlamm@gmail.com
Project-URL: Bug Tracker, https://github.com/hoangthanhlamm/multithread_parallel_processing
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests

# Multi-thread Parallel Processing

Library support parallel processing with multi-thread.

## Installation
```shell
$ pip3 install miltithread_parallel_processing
```

## Example

Example job to calculate sum of the squares of the first billion natural numbers.

```python
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()
```
