vtivrt.reader

Classes implementing connections to VRT sockets.

Members

class vtivrt.reader.VtiVrtReader(host: str, port: int = 9900, binary_point: int = None)

Bases: object

Represents a connection to a VRT streamer socket.

Variables:
  • binary_point – If not None, for any data packet with an integer data type, the data samples will be interpretted as fixed-point, with a fractional portion the size of this value, in bits.

  • sock – The connected socket.

  • buffered_context – A dict buffering context packets during calls to read_collate_context.

Parameters:
  • host – The hostname or IP address of the server to connect to.

  • port – The TCP port to connect to.

  • binary_point – If specified, and if the packet is a data packet with an integer data type, the data samples will be interpretted as fixed-point, with a fractional portion the size of this value, in bits.

fileno() int

Returns the file descriptor of the connected socket.

read(collate_context: bool = False) VtiVrtPacket

Read a VRT packet from the socket.

Parameters:

collate_context – If true, only return once a data packet has been received, and attach any context packets matching its stream_id to it. If false, return the first packet received, regardless of its type.

read_collate_context() VtiVrtPacket

Reads VRT packets from the socket until a data packet is received.

Any context packets received are saved in the buffered_context attribute. When a data packet is received, any context packets in buffered_context whose stream_id attribute matches that of the data packet will be removed from buffered_context and added to the packet’s context list.

read_one_packet() VtiVrtPacket

Reads one VRT packet from the socket.

class vtivrt.reader.VtiVrtThread(args: Iterable)

Bases: Thread

Reads VRT packets from a collection of sockets, and collates them by stream id.

Parameters:

args – The parameters for a connecting to a collection of VRT sockets. Each entry should be a tuple containing the arguments to the constructor of VtiVrtReader (hostname, port, binary_point); note that port and binary_point are optional.

_delete()

Remove current thread from the dict of currently running threads.

_set_tstate_lock()

Set a lock object which will be released by the interpreter when the underlying thread state (see pystate.h) gets deleted.

property daemon

A boolean value indicating whether this thread is a daemon thread.

This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when only daemon threads are left.

getName()

Return a string used for identification purposes only.

This method is deprecated, use the name attribute instead.

property ident

Thread identifier of this thread or None if it has not been started.

This is a nonzero integer. See the get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.

isDaemon()

Return whether this thread is a daemon.

This method is deprecated, use the daemon attribute instead.

is_alive()

Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. See also the module function enumerate().

join(timeout=None)

Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating-point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

property name

A string used for identification purposes only.

It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.

property native_id

Native integral thread ID of this thread, or None if it has not been started.

This is a non-negative integer. See the get_native_id() function. This represents the Thread ID as reported by the kernel.

num_packets(stream_ids: Iterable[int] = None)

Gets the minimum number of available packets among all specified stream_ids.

Parameters:

stream_ids – The stream_ids to get packets from. If unspecified, all known stream_ids will be queried.

read(num: int = None, stream_ids: Iterable[int] | Dict[int, str] = None, block: bool = False, timeout: float = None) Dict[int, List[VtiVrtPacket]] | Dict[str, List[VtiVrtPacket]]

Read packets from all specified stream_ids.

Parameters:
  • num – The number of packets to get for each stream_id. If None or not positive, the minimum available among all specified stream_ids will be used. If that is 0, 1 will be used.

  • stream_ids – The stream_ids to get packets from. If unspecified, packets will be returned from all known stream_ids. This may be a collection of stream id integers, or a dict mapping stream ids to channel names.

  • block – Whether to block if packets are missing from any specified stream_ids. If false, all available data will be returned immediately, and timeout will be ignored.

  • timeout – The maximum amount of seconds to wait for packets, if block is true.

Returns:

A dictionary mapping streams ids (or their associated channel names, if stream_ids was a dict) to lists of packets.

Raises:

TimeoutError – If block is true and timeout is exceeded.

run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

setDaemon(daemonic)

Set whether this thread is a daemon.

This method is deprecated, use the .daemon property instead.

setName(name)

Set the name string for this thread.

This method is deprecated, use the name attribute instead.

start()

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

stop()

Stop the thread.