Python Petri Nets — ELI5
Imagine a marble maze with special gates. Each gate has slots where marbles must sit before the gate opens. When enough marbles are in the right slots, the gate opens and the marbles roll through to new spots on the other side.
That’s essentially a Petri net. It models situations where multiple things can happen at the same time, but some things depend on other things finishing first.
Here’s a real example: making a sandwich.
You need bread and filling before you can assemble the sandwich. Getting bread and getting filling can happen at the same time (you grab the bread while someone else grabs the cheese). But “assemble sandwich” can only start when both are ready.
In Petri net terms:
- The spots where marbles sit are called “places” (bread ready, filling ready, sandwich assembled)
- The gates are called “transitions” (get bread, get filling, assemble)
- The marbles are called “tokens” — they represent resources or conditions being met
A transition “fires” (the gate opens) only when all its input places have enough tokens. When it fires, it removes tokens from the inputs and adds tokens to the outputs.
Why is this useful? Because real systems have lots of things happening simultaneously with complex dependencies. A factory floor, a computer network, a hospital workflow — they all have parallel activities that need to synchronize at certain points.
Regular flowcharts show one thing after another. Petri nets show things happening at the same time and where they need to wait for each other.
One thing to remember: Petri nets are like marble mazes where gates only open when the right combination of marbles arrives — they model parallel activities and synchronization in a way simple flowcharts can’t.
See Also
- Python Finite Automata How finite automata work like vending machines — they read input step by step and decide whether to accept or reject based on simple rules.
- Ci Cd Why big apps can ship updates every day without turning your phone into a glitchy mess — CI/CD is the behind-the-scenes quality gate and delivery truck.
- Containerization Why does software that works on your computer break on everyone else's? Containers fix that — and they're why Netflix can deploy 100 updates a day without the site going down.
- Python 310 New Features Python 3.10 gave programmers a shape-sorting machine, friendlier error messages, and cleaner ways to say 'this or that' in type hints.
- Python 311 New Features Python 3.11 made everything faster, error messages smarter, and let you catch several mistakes at once instead of stopping at the first one.