binary-husky/gpt_academic · warning · RuntimeError
程序终止。
Error message
程序终止。
What it means
Watchdog in predict_no_ui_long_connection for local models: observe_window[1] holds the last 'feed' timestamp; if the caller (UI) stops refreshing it for more than watch_dog_patience (5 s), the generator assumes the user cancelled and raises RuntimeError('程序终止。'). This is cooperative cancellation, not a crash — the model thread simply stops streaming.
Source
Thrown at request_llms/local_llm_class.py:262
what_gpt_answer = {}
what_gpt_answer["role"] = "assistant"
what_gpt_answer["content"] = history[index+1]
if what_i_have_asked["content"] != "":
if what_gpt_answer["content"] == "":
continue
history_feedin.append(what_i_have_asked)
history_feedin.append(what_gpt_answer)
else:
history_feedin[-1]['content'] = what_gpt_answer['content']
watch_dog_patience = 5 # 看门狗 (watchdog) 的耐心, 设置5秒即可
response = ""
for response in _llm_handle.stream_chat(query=inputs, history=history_feedin, max_length=llm_kwargs['max_length'], top_p=llm_kwargs['top_p'], temperature=llm_kwargs['temperature']):
if len(observe_window) >= 1:
observe_window[0] = response
if len(observe_window) >= 2:
if (time.time()-observe_window[1]) > watch_dog_patience:
raise RuntimeError("程序终止。")
return response
def predict(inputs:str, llm_kwargs:dict, plugin_kwargs:dict, chatbot:ChatBotWithCookies,
history:list=[], system_prompt:str='', stream:bool=True, additional_fn:str=None):
"""
refer to request_llms/bridge_all.py
"""
chatbot.append((inputs, ""))
_llm_handle = GetSingletonHandle().get_llm_model_instance(LLMSingletonClass)
chatbot[-1] = (inputs, load_message + "\n\n" + _llm_handle.get_state())
yield from update_ui(chatbot=chatbot, history=[])
if not _llm_handle.running:
raise RuntimeError(_llm_handle.get_state())
if additional_fn is not None:
from core_functional import handle_core_functionality
inputs, history = handle_core_functionality(View on GitHub (pinned to d6bde0fa54)
Solutions
- If cancellation was intended, no fix is needed — this is by design.
- If generation aborts unexpectedly, ensure the caller/UI keeps setting observe_window[1] = time.time() at least every few seconds while the response is still wanted.
- Pass an observe_window list of length 1 (observation only, no watchdog) when programmatic long calls don't need cancellation.
- For very slow models, understand the watchdog measures caller liveness, not model progress — do not 'fix' by ignoring it.
Example fix
# caller: keep the watchdog fed while consuming the stream
# before
for response in predict_no_ui_long_connection(inputs, llm_kwargs, observe_window=obs):
...
# after
obs[1] = time.time()
for response in predict_no_ui_long_connection(inputs, llm_kwargs, observe_window=obs):
obs[1] = time.time() # feed the watchdog each iteration
... Defensive patterns
Strategy: validation
Validate before calling
# pass a one-element window to run without the watchdog observe_window = [''] # no index 1 -> cancellation check disabled # or keep feeding it: observe_window = ['', time.time()]
Try / catch
try:
for r in predict_no_ui_long_connection(q, kw, observe_window=obs):
obs[1] = time.time()
except RuntimeError as e:
if str(e) == '程序终止。':
handle_user_cancel() # expected, not an error
else:
raise Prevention
- Refresh observe_window[1] on every iteration while consuming the stream.
- Treat this exception as cancellation, never as a model failure.
- Use a 1-element window for headless/programmatic calls.
When it happens
Trigger: Streaming from a local model while the front end stops updating observe_window[1] = time.time() for over 5 seconds: user pressed stop, the UI tab was closed/refreshed, or the calling plugin never maintains the second observe_window slot.
Common situations: User clicks 'Stop' during a slow local-model generation; gradio page closed mid-generation; a custom caller passes observe_window of length >= 2 but never refreshes index 1.
Related errors
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/88b5c11defed6626.
Report an issue: GitHub.