spinnman.connections package

Submodules

spinnman.connections.connection_listener module

class spinnman.connections.connection_listener.ConnectionListener(connection, n_processes=4)[source]

Bases: threading.Thread

Listens to a connection and calls callbacks with new messages when they arrive

Parameters:
  • connection – An AbstractListenable connection to listen to
  • n_processes – The number of threads to use when calling callbacks
add_callback(callback)[source]

Add a callback to be called when a message is received

Parameters:callback – A callable which takes a single parameter, which is the message received
close()[source]

Closes the listener. Note that this does not close the provider of the messages; this instead marks the listener as closed. The listener will not truly stop until the get message call returns.

run()[source]

spinnman.connections.scp_request_pipeline module

class spinnman.connections.scp_request_pipeline.SCPRequestPipeLine(connection, n_channels=1, intermediate_channel_waits=0, retry_codes=set([<SCPResult.RC_P2P_TIMEOUT: 142>, <SCPResult.RC_TIMEOUT: 134>, <SCPResult.RC_P2P_NOREPLY: 139>, <SCPResult.RC_LEN: 129>]), n_retries=3, packet_timeout=0.5)[source]

Bases: object

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 – The connection over which the communication is to take place
  • n_channels – The number of requests to send before checking for responses. If None, this will be determined automatically
  • intermediate_channel_waits – The number of outstanding responses to wait for before continuing sending requests. If None, this will be determined automatically
  • retry_codes – The set of response codes that will be retried
  • n_retries – The number of times to resend any packet for any reason before an error is triggered
  • packet_timeout – The number of elapsed seconds after sending a packet before it is considered a timeout.
finish()[source]

Indicate the end of the packets to be sent. This must be called to ensure that all responses are received and handled.

n_channels
n_resent
n_retry_code_resent
n_timeouts
send_request(request, callback, error_callback)[source]

Add an SCP request to the set to be sent

Parameters:
  • request – The SCP request to be sent
  • callback – A callback function to call when the response has been received; takes SCPResponse as a parameter, or None if the response doesn’t need to be processed
  • error_callback – A callback function to call when an error is found when processing the message; takes original SCPRequest, exception caught and a list of tuples of (filename, line number, function name, text) as a traceback

spinnman.connections.socket_address_with_chip module

class spinnman.connections.socket_address_with_chip.SocketAddressWithChip(hostname, chip_x, chip_y, port_num=17893)[source]

Bases: object

The address of a socket and an associated chip

chip_x

The x-coordinate of the chip

Returns:the x-coordinate
chip_y

The y-coordinate of the chip

Returns:the y-coordinate
hostname

The hostname of the socket

Returns:the hostname
port_num

The port number of the socket

Returns:the port

spinnman.connections.token_bucket module

class spinnman.connections.token_bucket.TokenBucket(tokens, fill_rate)[source]

Bases: object

An implementation of the token bucket algorithm.

>>> bucket = TokenBucket(80, 0.5)
>>> print bucket.consume(10)
True
Not thread safe.
Parameters:
  • tokens – the total tokens in the bucket
  • fill_rate – the rate in tokens/second that the bucket will be refilled.
consume(tokens, block=True)[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.

tokens

Module contents

class spinnman.connections.ConnectionListener(connection, n_processes=4)[source]

Bases: threading.Thread

Listens to a connection and calls callbacks with new messages when they arrive

Parameters:
  • connection – An AbstractListenable connection to listen to
  • n_processes – The number of threads to use when calling callbacks
add_callback(callback)[source]

Add a callback to be called when a message is received

Parameters:callback – A callable which takes a single parameter, which is the message received
close()[source]

Closes the listener. Note that this does not close the provider of the messages; this instead marks the listener as closed. The listener will not truly stop until the get message call returns.

run()[source]
class spinnman.connections.SCPRequestPipeLine(connection, n_channels=1, intermediate_channel_waits=0, retry_codes=set([<SCPResult.RC_P2P_TIMEOUT: 142>, <SCPResult.RC_TIMEOUT: 134>, <SCPResult.RC_P2P_NOREPLY: 139>, <SCPResult.RC_LEN: 129>]), n_retries=3, packet_timeout=0.5)[source]

Bases: object

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 – The connection over which the communication is to take place
  • n_channels – The number of requests to send before checking for responses. If None, this will be determined automatically
  • intermediate_channel_waits – The number of outstanding responses to wait for before continuing sending requests. If None, this will be determined automatically
  • retry_codes – The set of response codes that will be retried
  • n_retries – The number of times to resend any packet for any reason before an error is triggered
  • packet_timeout – The number of elapsed seconds after sending a packet before it is considered a timeout.
finish()[source]

Indicate the end of the packets to be sent. This must be called to ensure that all responses are received and handled.

n_channels
n_resent
n_retry_code_resent
n_timeouts
send_request(request, callback, error_callback)[source]

Add an SCP request to the set to be sent

Parameters:
  • request – The SCP request to be sent
  • callback – A callback function to call when the response has been received; takes SCPResponse as a parameter, or None if the response doesn’t need to be processed
  • error_callback – A callback function to call when an error is found when processing the message; takes original SCPRequest, exception caught and a list of tuples of (filename, line number, function name, text) as a traceback
class spinnman.connections.SocketAddressWithChip(hostname, chip_x, chip_y, port_num=17893)[source]

Bases: object

The address of a socket and an associated chip

chip_x

The x-coordinate of the chip

Returns:the x-coordinate
chip_y

The y-coordinate of the chip

Returns:the y-coordinate
hostname

The hostname of the socket

Returns:the hostname
port_num

The port number of the socket

Returns:the port
class spinnman.connections.TokenBucket(tokens, fill_rate)[source]

Bases: object

An implementation of the token bucket algorithm.

>>> bucket = TokenBucket(80, 0.5)
>>> print bucket.consume(10)
True
Not thread safe.
Parameters:
  • tokens – the total tokens in the bucket
  • fill_rate – the rate in tokens/second that the bucket will be refilled.
consume(tokens, block=True)[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.

tokens