Solving sudoku with multiprocessing

In this module, we're going to implement three functions. The first one simply solves a batch of sudoku puzzles, with no multiprocessing involved. We will use the results for benchmarking. The second and the third ones will use multiprocessing, with and without batch-solving, so we can appreciate the differences. Let's start:

# sudoku/process_solver.pyimport osfrom functools import reducefrom operator import concatfrom math import ceilfrom time import timefrom contextlib import contextmanagerfrom concurrent.futures import ProcessPoolExecutor, as_completedfrom unittest import TestCasefrom algo.solver import solve@contextmanagerdef timer():    t = time()    yield    tot = time() - t print(f'Elapsed time: {tot:.3f}s') ...

Get Learn Python Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.