An Event in Moler is aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nokia/moler/llms.txt
Use this file to discover all available pages before exploring further.
ConnectionObserver that runs continuously in the background, scanning connection output for a specific pattern. Unlike a Command, an event never writes anything to the connection — it only observes. This makes events ideal for catching asynchronous, unsolicited output: device reboots, alarm messages, prompt changes, or any other condition that can appear at any time.
How events differ from commands
Command | Event | |
|---|---|---|
| Sends data to connection? | Yes | No (passive) |
| Lifecycle | Short-lived: start → parse output → done | Long-lived: start → keep watching → cancel |
| Default timeout | Set by caller | ~100 years (effectively infinite) |
| Result | Single structured dict/list | List of all occurrences seen |
| Primary API | start() / () / await_done() | start() / callback / cancel() |
Event lifecycle
Events are started explicitly withstart() and run until they are cancelled, or until they have matched till_occurs_times times (if set).
Events have a default timeout of approximately 100 years. They are designed to run for the duration of a test, not to expire on their own.
Reacting with callbacks
The primary way to use events is to register a callback viaadd_event_occurred_callback(). Every time the event’s pattern matches a line on the connection, the callback is called.
The Wait4prompt event
Wait4prompt (moler.events.unix.wait4prompt) is the most commonly used built-in event. Devices use it internally to detect state transitions by watching for shell prompts. It extends the generic Wait4 event with a single prompt regex parameter.
| Key | Description |
|---|---|
line | The full line that matched |
matched | The substring that matched the pattern |
groups | Tuple of captured groups from the regex |
named_groups | Dict of named captured groups |
time | datetime of the match |
Limiting occurrences with till_occurs_times
Pass till_occurs_times=N to make the event finish automatically after it has matched N times. Once it has seen that many matches, it calls set_result() with the list of all occurrences and marks itself done — just like a command.
till_occurs_times=-1 the event runs indefinitely; you must cancel it explicitly.
Pause and resume
All events implementpause() and resume(). Devices call these internally during state transitions (when pause_prompts_event_on_state_change is enabled) to avoid spurious prompt matches while a transition command is running.
Retrieving occurrences
At any point you can inspect what the event has seen so far:Logging
Each occurrence is logged atINFO level by default. Call disable_log_occurrence() to suppress this if the event fires very frequently.
Commands
Active observers that send data and parse output
Devices
State machines that manufacture events for the current state