spinnman.connections package¶
Subpackages¶
- spinnman.connections.abstract_classes package
- spinnman.connections.udp_packet_connections package
- Module contents
BMPConnection
BootConnection
EIEIOConnection
IPAddressesConnection
SCAMPConnection
SDPConnection
UDPConnection
UDPConnection.close()
UDPConnection.get_receive_method()
UDPConnection.is_connected()
UDPConnection.is_ready_to_receive()
UDPConnection.local_ip_address
UDPConnection.local_port
UDPConnection.receive()
UDPConnection.receive_with_address()
UDPConnection.remote_ip_address
UDPConnection.remote_port
UDPConnection.send()
UDPConnection.send_to()
update_sdp_header_for_udp_send()
- Module contents
Module contents¶
- class spinnman.connections.ConnectionListener(connection: Listenable[T], n_processes: int = 4, timeout: float = 1)¶
-
Thread that listens to a connection and calls callbacks with new messages when they arrive.
- Parameters:
connection (Listenable) – A connection to listen to
n_processes (int) – The number of threads to use when calling callbacks
timeout (float) – How long to wait for messages before checking to see if the connection is to be terminated.
- add_callback(callback: Callable[[T], None]) None [source]¶
Add a callback to be called when a message is received.
- Parameters:
callback (Callable) – A callable which takes a single parameter, which is the message received; the result of the callback will be ignored.
- class spinnman.connections.SCPRequestPipeLine(connection: SCAMPConnection, n_channels: int = 1, intermediate_channel_waits: int = 0, n_retries: int = 10, packet_timeout: float = 1.0, non_fail_retry_codes: Set[SCPResult] | None = None)¶
Bases:
Generic
[R
]Allows a set of SCP requests to be grouped together in a communication across a number of channels for a given connection.
This class implements an SCP windowing, first suggested by Andrew Mundy. This extends the idea by having both send and receive windows. These are represented by the n_channels and the intermediate_channel_waits parameters respectively. This seems to help with the timeout issue; when a timeout is received, all requests for which a reply has not been received can also timeout.
- Parameters:
connection (SCAMPConnection) – The connection over which the communication is to take place
n_channels (int) – The number of requests to send before checking for responses. If None, this will be determined automatically
intermediate_channel_waits (int) – The number of outstanding responses to wait for before continuing sending requests. If None, this will be determined automatically
n_retries (int) – The number of times to resend any packet for any reason before an error is triggered
packet_timeout (float) – The number of elapsed seconds after sending a packet before it is considered a timeout.
non_fail_retry_codes (set(SCPResult) or None) – Codes that could retry but won’t fail, or None if there are no such codes
- finish() None [source]¶
Indicate the end of the packets to be sent. This must be called to ensure that all responses are received and handled.
- property n_channels: int¶
The number of requests to send before checking for responses.
- Return type:
- property n_retry_code_resent: int¶
The number of resends due to reasons for which automated retry is the correct response in-protocol.
- Return type:
- send_request(request: AbstractSCPRequest[R], callback: Callable[[R], None] | None, error_callback: Callable[[AbstractSCPRequest[R], Exception, TracebackType, SCAMPConnection], None]) None [source]¶
Add an SCP request to the set to be sent.
- Parameters:
request (AbstractSCPRequest) – The SCP request to be sent
callback (Callable) – A callback function to call when the response has been received; takes a
SCPResponse
as a parameter, or None if the response doesn’t need to be processederror_callback (Callable) – A callback function to call when an error is found when processing the message; takes the original
AbstractSCPRequest
, the exception caught and a list of tuples of (filename, line number, function name, text) as a traceback
- class spinnman.connections.TokenBucket(tokens: int, fill_rate: float)¶
Bases:
object
An implementation of the token bucket algorithm. Usage:
>>> bucket = TokenBucket(80, 0.5) >>> print(bucket.consume(10)) True
Not thread safe.
- Parameters:
- consume(tokens: int, block: bool = True) bool [source]¶
Consume tokens from the bucket. Returns True if there were sufficient tokens.
If there are not enough tokens and block is True, sleeps until the bucket is replenished enough to satisfy the deficiency.
If there are not enough tokens and block is False, returns False.
It is an error to consume more tokens than the bucket capacity.