Skip to content
Snippets Groups Projects
minion.py 542 B
Newer Older
Guilhem Saurel's avatar
Guilhem Saurel committed
#!/usr/bin/env python3
Guilhem Saurel's avatar
Guilhem Saurel committed

import time

from manager import QueueClient
Guilhem Saurel's avatar
Guilhem Saurel committed
from work import find_prime
Guilhem Saurel's avatar
Guilhem Saurel committed


class Minion(QueueClient):
    def run(self):
        while True:
            task = self.queue.get()
Guilhem Saurel's avatar
Guilhem Saurel committed
            start = time.perf_counter()
Guilhem Saurel's avatar
Guilhem Saurel committed
            print(f"start work on task {task}...")
Guilhem Saurel's avatar
Guilhem Saurel committed
            result = find_prime(task)
Guilhem Saurel's avatar
Guilhem Saurel committed
            print(
Guilhem Saurel's avatar
Guilhem Saurel committed
                f"Done ! The {task}-th prime number is {result} "
                f"(found in {time.perf_counter() - start:.3f}s)"
Guilhem Saurel's avatar
Guilhem Saurel committed
            )
Guilhem Saurel's avatar
Guilhem Saurel committed


Guilhem Saurel's avatar
Guilhem Saurel committed
if __name__ == "__main__":
Guilhem Saurel's avatar
Guilhem Saurel committed
    Minion().run()