Subscription#

class Subscription#

Bases: object

Iterate over (Node, AttributeValue) pairs from a subscription.

Set poll_interval_ms to read the selected attribute from nodes that sent no notification during the interval. Samples accumulate while Python is idle.

Poll results wait until the next interval or a matching notification. If either comparable timestamp shows the poll is strictly older, the poll is delivered first. Otherwise, the notification replaces it. Unmatched polls are retained.

After close(), you can still iterate over retained samples. A terminal native error follows those samples once. A deletion error raises in close().

Examples

>>> from instro.opcua import OpcUaClient
>>> with OpcUaClient.connect("opc.tcp://localhost:4840") as client:
...     paths = ["/Objects/Server/ServerStatus/CurrentTime"]
...     with client.subscribe(paths, publishing_interval_ms=500) as samples:
...         node, sample = next(samples)
...         print(node.node_id, sample.value)

Methods

close

Stop monitoring the nodes and finish cleanup.

close()#

Stop monitoring the nodes and finish cleanup.

Cleanup stops accepting notifications, finishes any admitted read, and retains accepted notifications and pending poll results for iteration. The caller that takes ownership of cleanup waits with the GIL released and defers Python signals. Concurrent callers can return before cleanup finishes. Cleanup succeeds if the session has disconnected or the server reports that the subscription is already absent.

Raises:

OpcUaError – The client could not delete the subscription on the server.