yera.events.stream

Event stream implementation for inter-process app communication.

Symbols

def await_input — Block until an input event is available and return it.
class EventStream — Inter-process event stream backed by multiprocessing queues.
def failure_exit_event_already_pushed — Return True if a nested app already pushed a failure exit event.
def is_restricted_stream — Return whether the current event stream is restricted (only certain block types allowed).
def push_input — Push an input event to the current stream.
def push_output — Push an output event to the current stream.
def push_text_input — Push a plain-text input event to the current stream.

await_input

await_input(
    timeout: float | None = None,
) → InputEvent

Block until an input event is available and return it.

EventStream

Inter-process event stream backed by multiprocessing queues.

Methods

push_output — Put an output event onto the queue.
push_input — Put an input event onto the queue.
pop_output — Remove and return the next output event, blocking up to timeout.
pop_input — Remove and return the next input event, blocking up to timeout.
has_output — Return True if there are output events queued.
has_input — Return True if there are input events queued.
iter_output — Yield all currently queued output events without blocking.
iter_output_blocking — Yield output events using blocking get(timeout). Reliable across processes.
set_current — Bind this stream to the current context variable.
get_current — Return the stream bound to the current context, raising if none is set.
build — Return the current stream if one exists, otherwise create and register a new one.

EventStream.push_output

push_output(
    event: OutputEvent,
) → None

Put an output event onto the queue.

EventStream.push_input

push_input(
    in_event: InputEvent,
) → None

Put an input event onto the queue.

EventStream.pop_output

pop_output(
    timeout: float | None = None,
) → OutputEvent

Remove and return the next output event, blocking up to timeout.

EventStream.pop_input

pop_input(
    timeout: float | None = None,
) → InputEvent

Remove and return the next input event, blocking up to timeout.

EventStream.has_output

has_output() → bool

Return True if there are output events queued.

EventStream.has_input

has_input() → bool

Return True if there are input events queued.

EventStream.iter_output

iter_output(
    timeout: float | None = None,
) → Iterator[OutputEvent]

Yield all currently queued output events without blocking.

EventStream.iter_output_blocking

iter_output_blocking(
    timeout: float = 0.5,
) → Iterator[OutputEvent]

Yield output events using blocking get(timeout). Reliable across processes.

Do not use iter_output() when the producer is in another process: Queue.empty() is unreliable across processes and the consumer may never see the event. This method blocks on get(timeout=...) so the exit event is received reliably.

EventStream.set_current

set_current() → None

Bind this stream to the current context variable.

EventStream.get_current

get_current() → EventStream

Return the stream bound to the current context, raising if none is set.

EventStream.build

build() → EventStream

Return the current stream if one exists, otherwise create and register a new one.

failure_exit_event_already_pushed

failure_exit_event_already_pushed() → bool

Return True if a nested app already pushed a failure exit event.

is_restricted_stream

is_restricted_stream() → bool

Return whether the current event stream is restricted (only certain block types allowed).

push_input

push_input(
    in_event: InputEvent,
) → None

Push an input event to the current stream.

push_output

push_output(
    event: OutputEvent,
) → None

Push an output event to the current stream.

push_text_input

push_text_input(
    text: str,
) → None

Push a plain-text input event to the current stream.