(grid, in_queue, out_queue)
| 157 | return count |
| 158 | |
| 159 | def simulate_pipeline(grid, in_queue, out_queue): |
| 160 | for y in range(grid.height): |
| 161 | for x in range(grid.width): |
| 162 | state = grid.get(y, x) |
| 163 | neighbors = count_neighbors(y, x, grid.get) |
| 164 | in_queue.put((y, x, state, neighbors)) # Fan-out |
| 165 | |
| 166 | in_queue.join() |
| 167 | item_count = out_queue.qsize() |
| 168 | |
| 169 | next_grid = Grid(grid.height, grid.width) |
| 170 | for _ in range(item_count): |
| 171 | item = out_queue.get() # Fan-in |
| 172 | y, x, next_state = item |
| 173 | if isinstance(next_state, Exception): |
| 174 | raise SimulationError(y, x) from next_state |
| 175 | next_grid.set(y, x, next_state) |
| 176 | |
| 177 | return next_grid |
| 178 | |
| 179 | |
| 180 | print("Example 4") |
no test coverage detected