Skip to content

Commit

Permalink
Add documentation to our ping wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dkfellows committed Aug 5, 2022
1 parent 0d39756 commit c9299b4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions spinn_utilities/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,26 @@


class Ping(object):
"""
Platform-independent ping support.
"""

#: The unreachable host cache.
unreachable = set()

@staticmethod
def ping(ipaddr):
"""
Send a ping (ICMP ECHO request) to the given host.
SpiNNaker boards support ICMP ECHO when booted.
:param str ipaddr:
The IP address to ping. Hostnames can be used, but are not
recommended.
:return:
return code of subprocess; 0 for success, anything else for failure
:rtype: int
"""
if platform.platform().lower().startswith("windows"):
cmd = "ping -n 1 -w 1 "
else:
Expand All @@ -36,6 +52,14 @@ def ping(ipaddr):

@staticmethod
def host_is_reachable(ipaddr):
"""
Test if a host is unreachable via ICMP ECHO. Note that this caches.
:param str ipaddr:
The IP address to ping. Hostnames can be used, but are not
recommended.
:rtype: bool
"""
if ipaddr in Ping.unreachable:
return False
tries = 0
Expand Down

0 comments on commit c9299b4

Please sign in to comment.