Skip to content

Commit cf4bfd1

Browse files
committed
Replace tenacity with custom retry function
1 parent 7bcbb20 commit cf4bfd1

File tree

1 file changed

+27
-7
lines changed
  • packages/python/plotly/plotly/io

1 file changed

+27
-7
lines changed

Diff for: packages/python/plotly/plotly/io/_orca.py

+27-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import atexit
2+
import functools
23
import json
34
import os
5+
import random
46
import socket
57
import subprocess
68
import sys
79
import threading
10+
import time
811
import warnings
9-
from copy import copy
1012
from contextlib import contextmanager
13+
from copy import copy
1114
from pathlib import Path
1215
from shutil import which
1316

14-
import tenacity
15-
1617
import plotly
1718
from plotly.files import PLOTLY_DIR, ensure_writable_plotly_dir
1819
from plotly.io._utils import validate_coerce_fig_to_dict
@@ -111,6 +112,28 @@ def find_open_port():
111112
return port
112113

113114

115+
def retry(min_wait=5, max_wait=10, max_delay=60000):
116+
def decorator(func):
117+
@functools.wraps(func)
118+
def wrapper(*args, **kwargs):
119+
start_time = time.time()
120+
121+
while True:
122+
try:
123+
return func(*args, **kwargs)
124+
except Exception as e:
125+
elapsed_time = time.time() - start_time
126+
if elapsed_time * 1000 >= max_delay:
127+
raise TimeoutError(f"Retry limit of {max_delay} milliseconds reached.") from e
128+
129+
wait_time = random.uniform(min_wait, max_wait)
130+
print(f"Retrying in {wait_time:.2f} seconds due to {e}...")
131+
time.sleep(wait_time)
132+
133+
return wrapper
134+
return decorator
135+
136+
114137
# Orca configuration class
115138
# ------------------------
116139
class OrcaConfig(object):
@@ -1357,10 +1380,7 @@ def ensure_server():
13571380
orca_state["shutdown_timer"] = t
13581381

13591382

1360-
@tenacity.retry(
1361-
wait=tenacity.wait_random(min=5, max=10),
1362-
stop=tenacity.stop_after_delay(60000),
1363-
)
1383+
@retry(min_wait=5, max_wait=10, max_delay=60000)
13641384
def request_image_with_retrying(**kwargs):
13651385
"""
13661386
Helper method to perform an image request to a running orca server process

0 commit comments

Comments
 (0)