def check_for_daemon(limit=10, delay=0.1, timeout=0.1, port=TCP_GIT_PORT):
 for _ in range(limit):
  time.sleep(delay)
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.settimeout(delay)
  try:
   s.connect(('localhost', port))
   return True
  except socket.timeout:
   pass
  except socket.error as e:
   if (getattr(e, 'errno', False) and (e.errno != errno.ECONNREFUSED)):
    raise
   elif (e.args[0] != errno.ECONNREFUSED):
    raise
  finally:
   s.close()
 return False

def check_for_daemon ( limit = 10 , delay = 0.1 , timeout = 0.1 , port = TCP_GIT_PORT ) : for _ in range ( limit ) : time . sleep ( delay ) s = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) s . settimeout ( delay ) try : s . connect ( ( 'localhost' , port ) ) return True except socket . timeout : pass except socket . error as e : if ( getattr ( e , 'errno' , False ) and ( e . errno != errno . ECONNREFUSED ) ) : raise elif ( e . args [ 0 ] != errno . ECONNREFUSED ) : raise finally : s . close ( ) return False
check for a running tcp daemon .