<s> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> import threading <EOL> import select <EOL> import sys <EOL> import logging <EOL> import socket <EOL> try : <EOL> import pybonjour <EOL> have_bonjour = True <EOL> except : <EOL> have_bonjour = False <EOL> class BonjourThread ( threading . Thread ) : <EOL> def __init__ ( self , port ) : <EOL> super ( BonjourThread , self ) . __init__ ( ) <EOL> self . name = socket . gethostname ( ) <EOL> self . regtype = "<STR_LIT>" <EOL> self . port = port <EOL> self . daemon = True <EOL> def register_callback ( self , sdRef , flags , errorCode , name , regtype , domain ) : <EOL> if errorCode == pybonjour . kDNSServiceErr_NoError : <EOL> logging . info ( "<STR_LIT>" . format ( name , regtype , self . port ) ) <EOL> def run ( self ) : <EOL> if not have_bonjour : <EOL> logging . warn ( "<STR_LIT>" ) <EOL> return <EOL> sdRef = pybonjour . DNSServiceRegister ( name = self . name , <EOL> regtype = self . regtype , <EOL> port = self . port , <EOL> callBack = self . register_callback ) <EOL> try : <EOL> try : <EOL> while True : <EOL> ready = select . select ( [ sdRef ] , [ ] , [ ] ) <EOL> if sdRef in ready [ <NUM_LIT:0> ] : <EOL> pybonjour . DNSServiceProcessResult ( sdRef ) <EOL> except KeyboardInterrupt : <EOL> pass <EOL> finally : <EOL> sdRef . close ( ) </s>
