binary-husky/gpt_academic · error · RuntimeError

程序终止。

Error message

程序终止。

What it means

Watchdog RuntimeError('程序终止。' - program terminated) in bridge_qianfan.predict_no_ui_long_connection: observe_window[1] holds the caller's heartbeat and if it is not refreshed within watch_dog_patience (=5) seconds the consume loop aborts. This is the standard cooperative-cancellation contract used across all bridges in this project; with Qianfan's fast SSE frames it almost always means the feeder thread stopped, not a slow server.

Source

Thrown at request_llms/bridge_qianfan.py:136

                raise ConnectionAbortedError(dec['error_msg'])  # 上下文太长导致 token 溢出
            elif ('error_code' in dec):
                raise RuntimeError(dec['error_msg'])


def predict_no_ui_long_connection(inputs:str, llm_kwargs:dict, history:list=[], sys_prompt:str="",
                                  observe_window:list=[], console_silence:bool=False):
    """
        ⭐多线程方法
        函数的说明请见 request_llms/bridge_all.py
    """
    watch_dog_patience = 5
    response = ""

    for response in generate_from_baidu_qianfan(inputs, llm_kwargs, history, sys_prompt):
        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, llm_kwargs, plugin_kwargs, chatbot, history=[], system_prompt='', stream = True, additional_fn=None):
    """
        ⭐单线程方法
        函数的说明请见 request_llms/bridge_all.py
    """
    chatbot.append((inputs, ""))

    if additional_fn is not None:
        from core_functional import handle_core_functionality
        inputs, history = handle_core_functionality(additional_fn, inputs, history, chatbot)

    yield from update_ui(chatbot=chatbot, history=history)
    # 开始接收回复
    try:
        response = f"[Local Message] 等待{model_name}响应中 ..."
        for response in generate_from_baidu_qianfan(inputs, llm_kwargs, history, system_prompt):

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Treat as expected cancellation if the user stopped the job - clean up partial state and exit
  2. Guarantee a feeder thread updates observe_window[1] = time.time() at least every few seconds while the result is still wanted
  3. Raise watch_dog_patience if intentional slow consumption is expected
  4. Catch RuntimeError and inspect the message before deciding to retry

Example fix

# caller contract
ow = ['', time.time()]
def feeder():
    while running:
        ow[1] = time.time()
        time.sleep(2)
Defensive patterns

Strategy: try-catch

Validate before calling

import time
ow[1] = time.time()
assert len(observe_window) >= 2, 'watchdog contract: observe_window[1] must be a heartbeat timestamp'

Try / catch

try:
    result = predict_no_ui_long_connection(inputs, llm_kwargs, history, observe_window=ow)
except RuntimeError as e:
    if '程序终止' in str(e):
        return ow[0]  # partial text; caller cancelled
    raise

Prevention

When it happens

Trigger: Caller thread that owns observe_window stopped updating the timestamp (user cancelled, UI closed, feeder thread crashed); exception in the consumer between yields leaving the dog unfed; debug breakpoint pausing the process >5s.

Common situations: User hits Stop during ERNIE Bot generation; plugin wraps predict_no_ui_long_connection without starting the feeder thread; Gradio session teardown.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/a13a93030ef0f8e9. Report an issue: GitHub.