Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multithread_parallel_processing-1.0.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file multithread_parallel_processing-1.0.0.tar.gz.

File metadata

File hashes

Hashes for multithread_parallel_processing-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6dbcad7b3fcb7a8120a118a90ce2934c503b4cf5fc964fb31dfeaf35625a721d
MD5 204bfbebb2d16ed2b122d23681597e0c
BLAKE2b-256 1614a3cd6e24f5c543f1bd00046208d497921826261b88d84e3c9fa644fe3f2f

See more details on using hashes here.

File details

Details for the file multithread_parallel_processing-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for multithread_parallel_processing-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f0cf3b722c2dd9bb69be0b588f7ea4e0887a4f6b5f695f67ea8c840d8959461
MD5 996466356dbde3d5d2b391094287edc3
BLAKE2b-256 91d40a775d145eec86a447a6d64465c13824887cd18d201f0fbe05bd0fc2effe

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page