|
1 | 1 | import atexit
|
| 2 | +import functools |
2 | 3 | import json
|
3 | 4 | import os
|
| 5 | +import random |
4 | 6 | import socket
|
5 | 7 | import subprocess
|
6 | 8 | import sys
|
7 | 9 | import threading
|
| 10 | +import time |
8 | 11 | import warnings
|
9 |
| -from copy import copy |
10 | 12 | from contextlib import contextmanager
|
| 13 | +from copy import copy |
11 | 14 | from pathlib import Path
|
12 | 15 | from shutil import which
|
13 | 16 |
|
14 |
| -import tenacity |
15 |
| - |
16 | 17 | import plotly
|
17 | 18 | from plotly.files import PLOTLY_DIR, ensure_writable_plotly_dir
|
18 | 19 | from plotly.io._utils import validate_coerce_fig_to_dict
|
@@ -111,6 +112,31 @@ def find_open_port():
|
111 | 112 | return port
|
112 | 113 |
|
113 | 114 |
|
| 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( |
| 128 | + f"Retry limit of {max_delay} milliseconds reached." |
| 129 | + ) from e |
| 130 | + |
| 131 | + wait_time = random.uniform(min_wait, max_wait) |
| 132 | + print(f"Retrying in {wait_time:.2f} seconds due to {e}...") |
| 133 | + time.sleep(wait_time) |
| 134 | + |
| 135 | + return wrapper |
| 136 | + |
| 137 | + return decorator |
| 138 | + |
| 139 | + |
114 | 140 | # Orca configuration class
|
115 | 141 | # ------------------------
|
116 | 142 | class OrcaConfig(object):
|
@@ -1357,10 +1383,7 @@ def ensure_server():
|
1357 | 1383 | orca_state["shutdown_timer"] = t
|
1358 | 1384 |
|
1359 | 1385 |
|
1360 |
| -@tenacity.retry( |
1361 |
| - wait=tenacity.wait_random(min=5, max=10), |
1362 |
| - stop=tenacity.stop_after_delay(60000), |
1363 |
| -) |
| 1386 | +@retry(min_wait=5, max_wait=10, max_delay=60000) |
1364 | 1387 | def request_image_with_retrying(**kwargs):
|
1365 | 1388 | """
|
1366 | 1389 | Helper method to perform an image request to a running orca server process
|
|
0 commit comments