GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — simple-task-queue/simple_task_queue.py at main · testdrivenio/simple-task-queue Expand file tree/ Copy pathsimple_task_queue.pyMore file actions 44 lines (33 loc) · 1.08 KB / Copy pathsimple_task_queue.pyFile metadata and controls44 lines (33 loc) · 1.08 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 # simple_task_queue.py import multiprocessing import time from tasks import get_word_counts PROCESSES = multiprocessing.cpu_count() - 1 NUMBER_OF_TASKS = 10 def process_tasks(task_queue): while not task_queue.empty(): book = task_queue.get() get_word_counts(book) return True def add_tasks(task_queue, number_of_tasks): for num in range(number_of_tasks): task_queue.put("pride-and-prejudice.txt") task_queue.put("heart-of-darkness.txt") task_queue.put("frankenstein.txt") task_queue.put("dracula.txt") return task_queue def run(): empty_task_queue = multiprocessing.Queue() full_task_queue = add_tasks(empty_task_queue, NUMBER_OF_TASKS) processes = [] print(f"Running with {PROCESSES} processes!") start = time.time() for n in range(PROCESSES): p = multiprocessing.Process(target=process_tasks, args=(full_task_queue,)) processes.append(p) p.start() for p in processes: p.join() print(f"Time taken = {time.time() - start:.10f}") if __name__ == "__main__": run() |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |