Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added client.wait_for_start() #87

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions aw_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,20 @@ def disconnect(self):
# Throw away old thread object, create new one since same thread cannot be started twice
self.request_queue = RequestQueue(self)

def wait_for_start(self, timeout: int = 10) -> None:
"""Wait for the server to start by trying to get the server info."""
start_time = datetime.now()
sleep_time = 0.1
while (datetime.now() - start_time).seconds < timeout:
try:
self.get_info()
break
except req.exceptions.ConnectionError:
sleep(sleep_time)
sleep_time *= 2
else:
raise Exception("Server did not start in time")


QueuedRequest = namedtuple("QueuedRequest", ["endpoint", "data"])
Bucket = namedtuple("Bucket", ["id", "type"])
Expand Down
Loading