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

Built Distribution

File details

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

File metadata

File hashes

Hashes for multithread_parallel_processing-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6c680234fdfded2af25e8b4e426f3289825bbac666f57e205ebd4fa495c1b4c0
MD5 57cac72d9516cd2b8108b5815a7d9490
BLAKE2b-256 a7107e711bd03fa66f199cfbea360c90a0cfb1a6a88ca2fa8ea5454de2daedd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for multithread_parallel_processing-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad1cb0ac611ae04dc67c4ceeeee5d715cc71c6e0b45f01ddfec3684812584a9f
MD5 4c9c3460e5c3f4341e51cd47b9f822dd
BLAKE2b-256 57e2d0800b1452627a8e504dc46f6c9531fb8cfdf5706b1694a8ca7d1c95af42

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