def api_has_bwctl(host, timeout=5, bind=None):
"""
Determine if a host is running the BWCTL daemon
"""
# Null implies localhost
if host is None:
host = "localhost"
# HACK: BWTCLBC
# If the environment says to bind to a certain address, do it.
if bind is None:
bind = os.environ.get('PSCHEDULER_LEAD_BIND_HACK', None)
for family in [socket.AF_INET, socket.AF_INET6]:
try:
with closing(socket.socket(family, socket.SOCK_STREAM)) as sock:
if bind is not None:
sock.bind((bind, 0))
sock.settimeout(timeout)
return sock.connect_ex((host, 4823)) == 0
except socket.error:
pass
return False
评论列表
文章目录