idolezal commited on
Commit
7d453b5
ยท
1 Parent(s): 1405ed9

Repeat when connection to check significance server is timed out

Browse files
Files changed (1) hide show
  1. server.py +46 -4
server.py CHANGED
@@ -20,6 +20,7 @@ from collections import namedtuple
20
  from xml.sax.saxutils import escape as xmlEscape, quoteattr as xmlQuoteAttr
21
  from threading import Lock
22
 
 
23
  import gradio as gr
24
  import pandas as pd
25
  from huggingface_hub import HfApi, snapshot_download
@@ -72,7 +73,42 @@ def check_significance_is_reachable():
72
  return False
73
  return True
74
 
75
- def check_significance_send_task(model_a_path, model_b_path):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  url = 'https://czechllm.fit.vutbr.cz/benczechmark-leaderboard/compare_significance/'
77
 
78
  # prepare and send request
@@ -84,7 +120,10 @@ def check_significance_send_task(model_a_path, model_b_path):
84
  'model_a': model_a_fp,
85
  'model_b': model_b_fp,
86
  }
87
- response = requests.post(url, files=files, timeout=60 * 5)
 
 
 
88
 
89
  # check response
90
  if response.status_code == 202:
@@ -97,9 +136,12 @@ def check_significance_send_task(model_a_path, model_b_path):
97
 
98
  return result_url
99
 
100
- def check_significance_wait_for_result(result_url):
101
  while True:
102
- response = requests.get(result_url, timeout=60 * 5)
 
 
 
103
  if response.status_code == 200:
104
  result = response.json()
105
  break
 
20
  from xml.sax.saxutils import escape as xmlEscape, quoteattr as xmlQuoteAttr
21
  from threading import Lock
22
 
23
+ import regex as re
24
  import gradio as gr
25
  import pandas as pd
26
  from huggingface_hub import HfApi, snapshot_download
 
73
  return False
74
  return True
75
 
76
+ REGEX_CONNECT_TIMEOUT_ERROR = re.compile(r"""ConnectTimeoutError\(.*'(.*timed out.*)'""")
77
+
78
+ def get_timeout_error_msg(exception):
79
+ e = exception
80
+
81
+ if isinstance(e, requests.exceptions.ConnectTimeout):
82
+ error_msg = REGEX_CONNECT_TIMEOUT_ERROR.search(str(e))
83
+ if error_msg:
84
+ error_msg = error_msg.group(1)
85
+ else:
86
+ error_msg = str(e).rsplit(":", 1)[-1].strip()
87
+ else:
88
+ error_msg = str(e).rsplit(":", 1)[-1].strip()
89
+
90
+ return error_msg
91
+
92
+ def check_significance_repeat_on_conn_timeout(repeat, fn, *args, **kwargs):
93
+ while True:
94
+ try:
95
+ result = fn(*args, **kwargs)
96
+ except requests.exceptions.Timeout as e:
97
+ error_msg = get_timeout_error_msg(e)
98
+
99
+ if repeat:
100
+ print(error_msg, f"({repeat = })")
101
+
102
+ if isinstance(repeat, int):
103
+ repeat -= 1
104
+
105
+ continue
106
+ else:
107
+ raise CheckSignificanceError(error_msg)
108
+ else:
109
+ return result
110
+
111
+ def check_significance_send_task(model_a_path, model_b_path, repeat_on_conn_timeout=10):
112
  url = 'https://czechllm.fit.vutbr.cz/benczechmark-leaderboard/compare_significance/'
113
 
114
  # prepare and send request
 
120
  'model_a': model_a_fp,
121
  'model_b': model_b_fp,
122
  }
123
+ response = check_significance_repeat_on_conn_timeout(
124
+ repeat_on_conn_timeout,
125
+ requests.post, url, files=files, timeout=60 * 5
126
+ )
127
 
128
  # check response
129
  if response.status_code == 202:
 
136
 
137
  return result_url
138
 
139
+ def check_significance_wait_for_result(result_url, repeat_on_conn_timeout=10):
140
  while True:
141
+ response = check_significance_repeat_on_conn_timeout(
142
+ repeat_on_conn_timeout,
143
+ requests.get, result_url, timeout=60 * 5
144
+ )
145
  if response.status_code == 200:
146
  result = response.json()
147
  break