• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / SpiNNMan / 6574804013

19 Oct 2023 12:47PM UTC coverage: 51.937% (+1.2%) from 50.777%
6574804013

Pull #327

github

Christian-B
typing changes
Pull Request #327: Type Annotations and Checking

105 of 1288 branches covered (0.0%)

Branch coverage included in aggregate %.

2375 of 2375 new or added lines in 180 files covered. (100.0%)

4775 of 8108 relevant lines covered (58.89%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

25.71
/spinnman/utilities/locate_connected_machine_ip_address.py
1
# Copyright (c) 2015 The University of Manchester
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     https://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
import time
1✔
16
import sys
1✔
17
import signal
1✔
18
import socket
1✔
19
from typing import Callable
1✔
20
from spinnman.connections.udp_packet_connections import IPAddressesConnection
1✔
21

22

23
def locate_connected_machine(handler: Callable[[str, float], None]):
1✔
24
    """
25
    Locates any SpiNNaker machines IP addresses from the auto-transmitted
26
    packets from non-booted SpiNNaker machines.
27

28
    :param ~collections.abc.Callable handler:
29
        A callback that decides whether to stop searching. The callback is
30
        given two arguments: the IP address found and the current time. It
31
        should return True if the search should cease.
32
    """
33

34
    connection = IPAddressesConnection()
×
35
    seen_boards = set()
×
36
    while True:
37
        ip_address = connection.receive_ip_address()
×
38
        now = time.time()
×
39
        if ip_address is not None and ip_address not in seen_boards:
×
40
            seen_boards.add(ip_address)
×
41
            if handler(ip_address, now):
×
42
                break
×
43

44

45
if __name__ == "__main__":
1!
46
    def _ctrlc_handler(sig, frame):  # @UnusedVariable
×
47
        """
48
        :param sig:
49
        :param frame:
50
        :return: Never returns as it causes a sys.exit()
51
        """
52
        # pylint: disable=unused-argument
53
        print("Exiting")
×
54
        sys.exit()
×
55

56
    def _print_connected(ip_address: str, timestamp: float):
×
57
        try:
×
58
            hostname = f" ({socket.gethostbyaddr(ip_address)[0]})"
×
59
        except Exception:  # pylint: disable=broad-except
×
60
            hostname = ""
×
61
        print(f"{ip_address}{hostname} at {timestamp}")
×
62
        return False
×
63

64
    print("The following addresses might be SpiNNaker boards "
×
65
          "(press Ctrl-C to quit):")
66
    signal.signal(signal.SIGINT, _ctrlc_handler)
×
67
    locate_connected_machine(handler=_print_connected)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc