On this page
Named lesser conduits๏
๐ก Intermediate ยท Lesson 41
Find a live job scope by name, then retire the name when that job ends. A name is a discovery address, not a new lifetime or a normal-root promotion. Names are exact, nonempty and unique within a frame. Supply them only when creating a lesser; prewarmed shells receive the new scope's name on acquisition. Cleanup removes the name before pool reuse. Keep the scope owner responsible for cleanup: a Cloud lookup borrows the object and does not extend its lifetime.
Before you run๏
Use the Intermediate guide for prerequisite concepts. Run from a checkout with Melder installed and Python 3.14 free-threading selected. The collection download includes the level's local helper modules.
Run the saved script๏
python UX_and_AIX_experiences/02_intermediate/41_named_lesser_conduits.py
py -3.14t UX_and_AIX_experiences/02_intermediate/41_named_lesser_conduits.py
Public surface๏
md.Spellbook.bind / conjure, md.Conduit.create_lesser_conduit / get_conduit_cloud / meld / cleanup / prewarm_lesser_conduits, ConduitCloud.get_conduit_by_name / has_conduit_name.
Code๏
1"""
2TIER: intermediate (41)
3GOAL: Find a live job scope by name, then retire the name when that job ends.
4 A name is a discovery address, not a new lifetime or a normal-root promotion.
5 Names are exact, nonempty and unique within a frame. Supply them only when
6 creating a lesser; prewarmed shells receive the new scope's name on acquisition.
7 Cleanup removes the name before pool reuse. Keep the scope owner responsible
8 for cleanup: a Cloud lookup borrows the object and does not extend its lifetime.
9SURFACE EXERCISED: md.Spellbook.bind / conjure, md.Conduit.create_lesser_conduit /
10 get_conduit_cloud / meld / cleanup / prewarm_lesser_conduits,
11 ConduitCloud.get_conduit_by_name / has_conduit_name.
12VERIFY: Runnable assertions cover lookup, collision, separate per-conduit values,
13 retirement and fresh values after pooled reuse. No Nexus or recorder setup.
14"""
15
16import melder as md
17
18
19class JobBuffer:
20 """Own the mutable work list for one scope; naming does not select its lifetime."""
21
22 def __init__(self) -> None:
23 """Start every newly created job buffer with independent empty state."""
24 self.items: list[str] = []
25
26
27def main() -> None:
28 """Run two jobs and reuse a finished scope under a new discovery name.
29
30 Contract:
31 Uses automatic mode to demonstrate that naming needs no dynamic mutation
32 policy. The root owns cleanup of remaining children even if an assertion fails.
33 Returns:
34 None.
35 """
36 book = md.Spellbook(aetheric_frame="named-jobs")
37 book.bind(spell=JobBuffer, existence="unique_per_conduit", permissions="create")
38 root = book.conjure(name="job-owner")
39 try:
40 root.prewarm_lesser_conduits(2)
41 cloud = root.get_conduit_cloud()
42 first = root.create_lesser_conduit(name="job-41")
43 second = root.create_lesser_conduit(name="job-42")
44 assert cloud.get_conduit_by_name("job-41") is first
45 assert cloud.get_conduit_by_name("job-42") is second
46
47 first_buffer = first.meld("JobBuffer")
48 second_buffer = second.meld("JobBuffer")
49 first_buffer.items.append("prepare invoice")
50 assert second_buffer is not first_buffer
51 assert second_buffer.items == []
52 print("Named lookup reaches the exact job; per-conduit values stay separate.")
53
54 try:
55 root.create_lesser_conduit(name="job-41")
56 except ValueError:
57 print("A duplicate active name is refused; the original job is still registered.")
58 else:
59 raise AssertionError("Duplicate active names must be rejected.")
60 assert cloud.get_conduit_by_name("job-41") is first
61
62 first.cleanup()
63 assert not cloud.has_conduit_name("job-41")
64 assert cloud.has_conduit_name("job-42")
65 replacement = root.create_lesser_conduit(name="job-43")
66 assert cloud.get_conduit_by_name("job-43") is replacement
67 assert replacement.meld("JobBuffer").items == []
68 assert not cloud.has_conduit_name("job-41")
69 print("Cleanup retires the old name; the next job begins with fresh scoped state.")
70
71 replacement.cleanup()
72 anonymous = root.create_lesser_conduit()
73 assert anonymous.name is None
74 assert not cloud.has_conduit_name("job-43")
75 anonymous.cleanup()
76 second.cleanup()
77 assert cloud.list_conduit_names() == ("job-owner",)
78 print("Anonymous scopes need no discovery entry. Names are not lifetime-matching tags.")
79 finally:
80 root.permanent_cleanup()
81
82
83if __name__ == "__main__":
84 main()
Check the outcome๏
The script contains its own assertions or demonstrated refusal paths. Run it to evaluate those checks against your installed version. The code above is taken directly from the saved file; no run output is invented here.