Skip to content

Commit f957343

Browse files
Allow user to configure poll interval
1 parent 58d881c commit f957343

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

replicate/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def __init__(self, api_token=None) -> None:
1919
self.base_url = os.environ.get(
2020
"REPLICATE_API_BASE_URL", "https://api.replicate.com"
2121
)
22+
self.poll_interval = float(os.environ.get("REPLICATE_POLL_INTERVAL", "0.5"))
2223

2324
# TODO: make thread safe
2425
self.session = requests.Session()

replicate/prediction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Prediction(BaseModel):
2424
def wait(self):
2525
"""Wait for prediction to finish."""
2626
while self.status not in ["succeeded", "failed", "canceled"]:
27-
time.sleep(0.5)
27+
time.sleep(self._client.poll_interval)
2828
self.reload()
2929

3030
def output_iterator(self) -> Iterator[Any]:
@@ -36,7 +36,7 @@ def output_iterator(self) -> Iterator[Any]:
3636
for output in new_output:
3737
yield output
3838
previous_output = output
39-
time.sleep(0.5)
39+
time.sleep(self._client.poll_interval)
4040
self.reload()
4141

4242
if self.status == "failed":

0 commit comments

Comments
 (0)