소스 검색

print a warning if stream task ever times out

Alex Cheema 1 년 전
부모
커밋
d8c40bb4f1
1개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. 4 1
      exo/api/chatgpt_api.py

+ 4 - 1
exo/api/chatgpt_api.py

@@ -200,7 +200,10 @@ class ChatGPTAPI:
                 _, tokens, _ = await callback.wait(on_result, timeout=self.response_timeout_secs)
                 if stream_task: # in case there is still a stream task running, wait for it to complete
                     if DEBUG >= 2: print(f"Pending stream task. Waiting for stream task to complete.")
-                    await stream_task
+                    try:
+                        await asyncio.wait_for(stream_task, timeout=30)
+                    except asyncio.TimeoutError:
+                        print("WARNING: Stream task timed out. This should not happen.")
                 await response.write_eof()
                 return response
             else: