import time import socket show = True for _ in range(30): try: socket.create_connection(('localhost', 8010), timeout=1) break except Exception as e: time.sleep(1) if show: print('waiting for frappy websocket') show = False else: print('failed')