Skip to content

Commit

Permalink
[cirque] Wait server up before sending commands (#10762)
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing authored and pull[bot] committed Oct 22, 2021
1 parent 3ef8011 commit 2838960
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import sys
import subprocess
import logging
import time
import click
from pathlib import Path
from dataclasses import dataclass
from enum import Enum
from multiprocessing.connection import Listener, Client
Expand Down Expand Up @@ -73,6 +75,7 @@ def __call__(self):


SERVER_ADDRESS = "/tmp/cirque-helper.socket"
CLIENT_WAIT_TIMEOUT_SECONDS = 5


def CommandFactory(args):
Expand Down Expand Up @@ -105,6 +108,13 @@ def ServerMain(args):
def ClientMain(args):
if len(args) == 0:
sys.exit(1)
# The server may start very slowly, wait for a few seconds to see if the server will start.
for _ in range(CLIENT_WAIT_TIMEOUT_SECONDS):
socks = Path(SERVER_ADDRESS)
if socks.exists():
break
time.sleep(1)
# If the address does not exist, Client constructor will throw an exception, so no need to add a flag.
with Client(SERVER_ADDRESS) as conn:
conn.send(args)
res = conn.recv()
Expand Down

0 comments on commit 2838960

Please sign in to comment.