Hand Off to a Resource
A handoff passes an order from one resource to the next without letting go of the first too early. Here a picker carries each order to a packing bench. The picker stays with the order until the bench is free. For a moment the order holds both resources, and then it releases the picker.

Before You Start
- Competing Resources measures what holding two resources costs.
- Several Resources describes
keepand the rule on the order of acquisition.
Steps
Keep the Picker When the First Task Ends
Give the first task the resource and keep it: pick holds the picker and hands it to the next task.
Ask for the Bench While Holding the Picker
Give the next task the second resource: pack waits for the bench while the order still holds the picker, and gives the picker back once it publishes started.
In the low-level API, pick passes its granted request to pack, which releases it in place of a with block:
Acquire the Resources in the Same Order
Acquire the two resources in the same order everywhere. A task that takes the bench first and the picker second does not stop the model from loading: the model logs one WARNING, from the logger desflow.builder.context, because two orders could then wait for each other for ever. A resource held with seize counts as held for this check.
Know When the Kept Unit Goes Back
Know when the kept unit goes back. The picker stays held until pack starts. A child flow that a task starts with wait: {task: ...} gives back only the units its own tasks asked for, so it never gives back a unit that its parent kept.
Check the Result
Save the files from Full Files and run desflow run multi_resource_handoffs.yaml, python multi_resource_handoffs.py or python multi_resource_handoffs_low_level.py. Each runs 30 simulated seconds at once and prints each event, and the three print the same events, because they use the same seed, 42.
Each order is queued for the picker, picked, queued for the bench and packed, in that order. Orders arrive about once a second, and the one bench takes 4 seconds to pack each, so it can pack only one order every 4 seconds. The bench is therefore the bottleneck: an order that waits for the bench keeps the picker, and the orders behind it wait for the picker.
A task that needs both resources for the whole of its work lists them instead, resource: [picker, bench]. The competing-resources example on Several Resources has both kinds.
Full Files
Full files
| docs/snippets/guides/multi_resource_handoffs_low_level.py | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |