MCPcopy Index your code
hub / github.com/bslatkin/effectivepython / simulate_phased_pipeline

Function simulate_phased_pipeline

example_code/item_073.py:339–357  ·  view source on GitHub ↗
(grid, in_queue, logic_queue, out_queue)

Source from the content-addressed store, hash-verified

337
338print("Example 9")
339def simulate_phased_pipeline(grid, in_queue, logic_queue, out_queue):
340 for y in range(grid.height):
341 for x in range(grid.width):
342 state = grid.get(y, x)
343 item = (y, x, state, grid.get)
344 in_queue.put(item) # Fan-out
345
346 in_queue.join()
347 logic_queue.join() # Pipeline sequencing
348 item_count = out_queue.qsize()
349
350 next_grid = LockingGrid(grid.height, grid.width)
351 for _ in range(item_count):
352 y, x, next_state = out_queue.get() # Fan-in
353 if isinstance(next_state, Exception):
354 raise SimulationError(y, x) from next_state
355 next_grid.set(y, x, next_state)
356
357 return next_grid
358
359
360print("Example 10")

Callers 1

item_073.pyFile · 0.85

Calls 5

setMethod · 0.95
SimulationErrorClass · 0.85
putMethod · 0.80
LockingGridClass · 0.70
getMethod · 0.45

Tested by

no test coverage detected