vidhubcontrol.common¶
- class vidhubcontrol.common.ConnectionManager(*args, **kwargs)[source]¶
Bases:
pydispatch.dispatch.DispatcherA manager for tracking and waiting for
connection statesA
asyncio.Conditionis used to to notify any waiting tasks of changes tostate. This requires the underlying lock to beacquiredbefore calling any of the waiter or setter methods andreleasedafterwards.This class supports the asynchronous context manager protocol for use in
async withstatements.- Events
- state_changed(self: ConnectionManager, state: ConnectionState)¶
Emitted when the value of
statehas changed
- async acquire()[source]¶
Acquire the lock
This method blocks until the lock is unlocked, then sets it to locked and returns True.
- release()[source]¶
Release the lock
- Raises
RuntimeError – if called on an unlocked lock
- async set_failure(reason: Any, exc: Optional[Exception] = None, state: Optional[Union[vidhubcontrol.common.ConnectionState, str]] = ConnectionState.None)[source]¶
Set
stateto indicate a failure- Parameters
reason – A description of the failure
exc – The Exception that caused the failure (if available)
state – The new state to set. Must include
ConnectionState.failure
- Raises
RuntimeError – If the lock is not
acquiredbefore calling this method
- async set_state(state: Union[vidhubcontrol.common.ConnectionState, str])[source]¶
Set the
stateto the given valueThe state argument may be either a
ConnectionStatemember or a string. (seeConnectionState.from_str())- Raises
RuntimeError – If the lock is not
acquiredbefore calling this method
- property state: vidhubcontrol.common.ConnectionState¶
The current state
- async syncronize(other: vidhubcontrol.common.ConnectionManager)[source]¶
Copy the
stateand failure values of anotherConnectionManagerNote
The lock must not be acquired before calling this method.
- async wait(timeout: Optional[float] = None) vidhubcontrol.common.ConnectionState[source]¶
Block until the next time
statechanges and return the value- Parameters
timeout – If given, the number of seconds to wait. Otherwise, this will wait indefinitely
- Raises
asyncio.TimeoutError – If timeout is given and no state changes occured
RuntimeError – If the lock is not
acquiredbefore calling this method
- async wait_for(state: Union[vidhubcontrol.common.ConnectionState, str], timeout: Optional[float] = None) vidhubcontrol.common.ConnectionState[source]¶
Wait for a specific state
The state argument may be a
ConnectionStatemember or string as described inConnectionState.from_str().If the given state is
compoundor thestateis set as compound, this will wait until all members from the state argument are contained within thestatevalue.- Parameters
state – The state to wait for
timeout – If given, the number of seconds to wait. Otherwise, this will wait indefinitely
- Raises
asyncio.TimeoutError – If timeout is given and no matching state changes were found
RuntimeError – If the lock is not
acquiredbefore calling this method
- async wait_for_disconnected(timeout: Optional[float] = None) vidhubcontrol.common.ConnectionState[source]¶
Wait for
ConnectionState.not_connected- Parameters
timeout – If given, the number of seconds to wait. Otherwise, this will wait indefinitely
- Raises
asyncio.TimeoutError – If timeout is given and no matching state changes were found
RuntimeError – If the lock is not
acquiredbefore calling this method
- async wait_for_established(timeout: Optional[float] = None) vidhubcontrol.common.ConnectionState[source]¶
Wait for either a success (
ConnectionState.connected) or failure (ConnectionState.failure)- Parameters
timeout – If given, the number of seconds to wait. Otherwise, this will wait indefinitely
- Raises
asyncio.TimeoutError – If timeout is given and no matching state changes were found
RuntimeError – If the lock is not
acquiredbefore calling this method
- class vidhubcontrol.common.ConnectionState(value)[source]¶
Bases:
enum.IntFlagEnum to describe various connection states
Members may be combined using bitwise operators (&, |, ^, ~)
- connected = 8¶
Indicates the connection is active
- connecting = 2¶
Indicates an attempt to connect is being made
- disconnecting = 4¶
Indicates the connection is being closed
- failure = 16¶
Indicates an error occured
- classmethod from_str(s: str) vidhubcontrol.common.ConnectionState[source]¶
Create a
ConnectionStatemember by name(s)Combined states can be created by separating their names with a “|”
>>> from vidhubcontrol.common import ConnectionState >>> ConnectionState.connected | ConnectionState.not_connected <ConnectionState.connected|not_connected: 9> >>> ConnectionState.disconnecting | ConnectionState.failure <ConnectionState.failure|disconnecting: 20> >>> # This combination is already defined as "waiting" >>> ConnectionState.connecting | ConnectionState.disconnecting <ConnectionState.waiting: 6>
- property is_connected: bool¶
Convenience property evaluating as True if
self == ConnectionState.connected
- not_connected = 1¶
Indicates there is no connection and no connection attempts are being made
- waiting = 6¶
Indicates the connection is either
connectingordisconnecting
- class vidhubcontrol.common.SyncronizedConnectionManager(*args, **kwargs)[source]¶
Bases:
vidhubcontrol.common.ConnectionManagerA connection manager that syncronizes itself with another
- property other: Optional[vidhubcontrol.common.ConnectionManager]¶
The manager currently being syncronized to
- async set_other(other: Optional[vidhubcontrol.common.ConnectionManager])[source]¶
Set the manager to syncronize with
This binds to the
state_changed()event of other and calls thesyncronize()method whenever the state of the other manager changes.If
Noneis given,stateis set tonot_connectedNote
The lock must not be acquired before calling this method