@@ -202,19 +202,26 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False):
202202 # Poll the status API until the build is completed or failed
203203 stream_event_counter = 0
204204 fail_counter = 0
205+ warned_last = False
206+ timeout = 10.0 ;
207+
205208 if wait :
206209 while True :
207210 logger .info ("Polling build status..." )
208- status_resp = requests .get (
209- build_status_url ,
210- auth = (None , chipflow_api_key )
211- )
212- if status_resp .status_code != 200 :
213- fail_counter += 1
214- logger .error (f"Failed to fetch build status { fail_counter } times: { status_resp .text } " )
215- if fail_counter > 5 :
216- logger .error (f"Failed to fetch build status { fail_counter } times. Exiting." )
217- raise ChipFlowError ("Error while checking build status." )
211+ try :
212+ status_resp = requests .get (
213+ build_status_url ,
214+ auth = (None , chipflow_api_key ),
215+ timeout = timeout
216+ )
217+ if status_resp .status_code != 200 :
218+ fail_counter += 1
219+ logger .error (f"Failed to fetch build status { fail_counter } times: { status_resp .text } " )
220+ if fail_counter > 5 :
221+ logger .error (f"Failed to fetch build status { fail_counter } times. Exiting." )
222+ raise ChipFlowError ("Error while checking build status." )
223+ except requests .Timeout :
224+ continue #go round again
218225
219226 status_data = status_resp .json ()
220227 build_status = status_data .get ("status" )
@@ -232,26 +239,31 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False):
232239 # time.sleep(10)
233240 # Attempt to stream logs rather than time.sleep
234241 try :
235- if stream_event_counter > 1 :
242+ if stream_event_counter > 1 and not warned_last :
236243 logger .warning ("Log streaming may have been interrupted. Some logs may be missing." )
237244 logger .warning (f"Check { build_url } " )
238- stream_event_counter += 1
245+ warned_last = True
239246 with requests .get (
240247 log_stream_url ,
241248 auth = (None , chipflow_api_key ),
242- stream = True
249+ stream = True , timeout = timeout
243250 ) as log_resp :
244251 if log_resp .status_code == 200 :
252+ warned_last = False
245253 for line in log_resp .iter_lines ():
246254 if line :
247255 print (line .decode ("utf-8" )) # Print logs in real-time
248256 sys .stdout .flush ()
249257 else :
250258 logger .warning (f"Failed to stream logs: { log_resp .text } " )
259+ stream_event_counter += 1
260+ except requests .Timeout as e :
261+ continue #go round again
251262 except requests .RequestException as e :
252263 logger .error (f"Error while streaming logs: { e } " )
264+ stream_event_counter += 1
253265 pass
254- time .sleep (10 ) # Wait before polling again
266+ time .sleep (0.5 ) # Wait before polling again
255267 else :
256268 # Log detailed information about the failed request
257269 logger .error (f"Request failed with status code { resp .status_code } " )
0 commit comments