Don't constantly retry socket

This commit is contained in:
Jake Howard 2018-12-14 19:07:39 +00:00
parent 28a127b619
commit c17484b0ec
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -22,13 +22,7 @@ WORKER_SERVER_SOCKET = os.path.join(BASE_SOCKET_DIR, "catfish.sock")
def send_to_server(payload): def send_to_server(payload):
with socket.socket(socket.AF_UNIX, type=socket.SOCK_STREAM) as sock: with socket.socket(socket.AF_UNIX, type=socket.SOCK_STREAM) as sock:
while True: sock.connect(WORKER_SERVER_SOCKET)
try:
sock.connect(WORKER_SERVER_SOCKET)
break
except ConnectionRefusedError:
time.sleep(0.1)
sock.sendall(ujson.dumps(payload).encode() + NEW_LINE) sock.sendall(ujson.dumps(payload).encode() + NEW_LINE)
return read_all_from_socket(sock) return read_all_from_socket(sock)