On this page

Config conduit lifecycle hooks๏ƒ

๐ŸŸก Intermediate ยท Lesson 33

SpellbookConfiguration hooks, family 2: the CONDUIT LIFECYCLE. Five moments of a conduit's life are observable: on_conduit_pre_created / on_conduit_post_created / on_conduit_activated at conjure, and on_conduit_cleanup_start / on_conduit_cleanup_complete at the end. Register before conjure; watch the whole life.

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/33_config_conduit_lifecycle_hooks.py
py -3.14t UX_and_AIX_experiences/02_intermediate/33_config_conduit_lifecycle_hooks.py

Download this collection ยท Source on GitHub

Public surface๏ƒ

conduit lifecycle hooks, firing order

Code๏ƒ

 1"""
 2TIER: intermediate (33)
 3GOAL: SpellbookConfiguration hooks, family 2: the CONDUIT LIFECYCLE.
 4      Five moments of a conduit's life are observable:
 5        on_conduit_pre_created / on_conduit_post_created /
 6        on_conduit_activated at conjure, and
 7        on_conduit_cleanup_start / on_conduit_cleanup_complete at the
 8        end. Register before conjure; watch the whole life.
 9SURFACE EXERCISED: conduit lifecycle hooks, firing order
10"""
11import melder as md
12
13
14class Anything:
15    pass
16
17
18def main() -> None:
19    moments = []
20
21    book = md.Spellbook()
22    config = book.get_configuration()
23    for name in ("on_conduit_pre_created", "on_conduit_post_created",
24                 "on_conduit_activated", "on_conduit_cleanup_start",
25                 "on_conduit_cleanup_complete"):
26        config.add_hook(book.id, name,
27                        (lambda n: lambda *a, **k: moments.append(n))(name))
28
29    book.bind(spell=Anything, existence="unique")
30    conduit = book.conjure()
31    print("after conjure:", moments)
32
33    conduit.cleanup()
34    print("after cleanup:", moments)
35    assert moments.index("on_conduit_pre_created") < moments.index(
36        "on_conduit_cleanup_start")
37    print("a conduit's whole life, observed in order")
38
39
40if __name__ == "__main__":
41    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.

More intermediate examples ยท Level guide