Observe which process performs a calculation.
Prototype: square_with_pid(value) accepts an integer and returns (value * value, os.getpid()). Define this function at module scope so spawned workers can import it. Direct calls run in the calling process.
Final: process_squares(values, workers=2) uses ProcessPoolExecutor with multiprocessing.get_context("spawn") and the module-level worker above. Return a list of (square, worker_pid) pairs in input order. Each worker PID must differ from the calling process's PID; no specific number of distinct workers is promised. Do not modify the input. workers is a positive integer; raise ValueError below 1, including on empty input. Empty input returns []. Negative integers and duplicates are valid. Join and shut down the pool before returning. Example values [2, -3] give squares 4, 9 with child PIDs. No speed assertion is tested.
This exercise starts native threads or processes, which browser Python does not support. Download your code and tests, then run the command below.
python3 main.py