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 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.