NetworkTableListener
- class ntcore.NetworkTableListener
Bases:
pybind11_object
Event listener. This calls back to a callback function when an event matching the specified mask occurs. The callback function is called asynchronously on a separate thread, so it’s important to use synchronization or atomics when accessing any shared state from the callback function.
- close() None
Destroys the listener
- static createConnectionListener(inst: ntcore._ntcore.NetworkTableInstance, immediate_notify: bool, listener: Callable[[ntcore._ntcore.Event], None]) ntcore._ntcore.NetworkTableListener
Create a connection listener.
- Parameters:
inst – instance
immediate_notify – notify listener of all existing connections
listener – listener function
- Returns:
Listener
- static createListener(*args, **kwargs)
Overloaded function.
createListener(inst: ntcore._ntcore.NetworkTableInstance, prefixes: List[str], mask: typing.SupportsInt, listener: Callable[[ntcore._ntcore.Event], None]) -> ntcore._ntcore.NetworkTableListener
Create a listener for changes to topics with names that start with any of the given prefixes. This creates a corresponding internal subscriber with the lifetime of the listener.
- Parameters:
inst – Instance
prefixes – Topic name string prefixes
mask – Bitmask of EventFlags values
listener – Listener function
- Returns:
Listener
createListener(topic: ntcore._ntcore.Topic, mask: typing.SupportsInt, listener: Callable[[ntcore._ntcore.Event], None]) -> ntcore._ntcore.NetworkTableListener
Create a listener for changes on a particular topic. This creates a corresponding internal subscriber with the lifetime of the listener.
- Parameters:
topic – Topic
mask – Bitmask of EventFlags values
listener – Listener function
- Returns:
Listener
createListener(subscriber: ntcore._ntcore.Subscriber, mask: typing.SupportsInt, listener: Callable[[ntcore._ntcore.Event], None]) -> ntcore._ntcore.NetworkTableListener
Create a listener for topic changes on a subscriber. This does NOT keep the subscriber active.
- Parameters:
subscriber – Subscriber
mask – Bitmask of EventFlags values
listener – Listener function
- Returns:
Listener
createListener(subscriber: ntcore._ntcore.MultiSubscriber, mask: typing.SupportsInt, listener: Callable[[ntcore._ntcore.Event], None]) -> ntcore._ntcore.NetworkTableListener
Create a listener for topic changes on a subscriber. This does NOT keep the subscriber active.
- Parameters:
subscriber – Subscriber
mask – Bitmask of EventFlags values
listener – Listener function
- Returns:
Listener
createListener(entry: ntcore._ntcore.NetworkTableEntry, mask: typing.SupportsInt, listener: Callable[[ntcore._ntcore.Event], None]) -> ntcore._ntcore.NetworkTableListener
Create a listener for topic changes on an entry.
- Parameters:
entry – Entry
mask – Bitmask of EventFlags values
listener – Listener function
- Returns:
Listener
- static createLogger(inst: ntcore._ntcore.NetworkTableInstance, minLevel: SupportsInt, maxLevel: SupportsInt, listener: Callable[[ntcore._ntcore.Event], None]) ntcore._ntcore.NetworkTableListener
Create a listener for log messages. By default, log messages are sent to stderr; this function sends log messages with the specified levels to the provided callback function instead. The callback function will only be called for log messages with level greater than or equal to minLevel and less than or equal to maxLevel; messages outside this range will be silently ignored.
- Parameters:
inst – instance
minLevel – minimum log level
maxLevel – maximum log level
listener – listener function
- Returns:
Listener
- static createTimeSyncListener(inst: ntcore._ntcore.NetworkTableInstance, immediate_notify: bool, listener: Callable[[ntcore._ntcore.Event], None]) ntcore._ntcore.NetworkTableListener
Create a time synchronization listener.
- Parameters:
inst – instance
immediate_notify – notify listener of current time synchronization value
listener – listener function
- Returns:
Listener
- getHandle() int
Gets the native handle.
- Returns:
Handle
- waitForQueue(timeout: SupportsFloat) bool
Wait for the listener queue to be empty. This is primarily useful for deterministic testing. This blocks until either the listener queue is empty (e.g. there are no more events that need to be passed along to callbacks or poll queues) or the timeout expires.
- Parameters:
timeout – timeout, in seconds. Set to 0 for non-blocking behavior, or a negative value to block indefinitely
- Returns:
False if timed out, otherwise true.