def _start_beacon(port=None):
"""Start a beacon thread within this process if no beacon is currently
running on this machine.
In general this is called automatically when an attempt is made to
advertise or discover. It might be convenient, though, to call this
function directly if you want to have a process whose only job is
to host this beacon so that it doesn't shut down when other processes
shut down.
"""
global _beacon
if _beacon is None:
_logger.debug("About to start beacon with port %s", port)
try:
_beacon = _Beacon(port)
except (OSError, socket.error) as exc:
if exc.errno == errno.EADDRINUSE:
_logger.warn("Beacon already active on this machine")
#
# _remote_beacon is simply a not-None sentinel value
# to distinguish between the case where we have not
# yet started a beacon and where we have found one
# in another process.
#
_beacon = _remote_beacon
else:
raise
else:
_beacon.start()
评论列表
文章目录