binary-husky/gpt_academic · error · RuntimeError

程序终止。

Error message

程序终止。

What it means

Watchdog RuntimeError('程序终止。') in bridge_skylark2.predict_no_ui_long_connection: while iterating YUNQUERequestInstance.generate, the heartbeat timestamp observe_window[1] exceeded watch_dog_patience (5s) without being fed, aborting the loop. Standard cooperative-cancellation mechanism shared by all bridges; with Skylark2's Volcano Engine streaming it fires on caller-side cancellation or a stalled feeder thread.

Source

Thrown at request_llms/bridge_skylark2.py:30

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 = ""

    if validate_key() is False:
        raise RuntimeError('请配置YUNQUE_SECRET_KEY')

    from .com_skylark2api import YUNQUERequestInstance
    sri = YUNQUERequestInstance()
    for response in sri.generate(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, ""))
    yield from update_ui(chatbot=chatbot, history=history)

    # 尝试导入依赖,如果缺少依赖,则给出安装建议
    try:
        check_packages(["zhipuai"])
    except:
        yield from update_ui_latest_msg(f"导入软件依赖失败。使用该模型需要额外依赖,安装方法```pip install --upgrade zhipuai```。",
                                         chatbot=chatbot, history=history, delay=0)
        return

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. On genuine cancellation, catch RuntimeError, discard partial output, and exit gracefully
  2. Start a daemon thread that writes time.time() into observe_window[1] every 1-2s while the result is wanted
  3. Increase watch_dog_patience for slow Volcano routes
  4. Distinguish this from provider errors by matching the '程序终止' message before retrying

Example fix

# before
result = predict_no_ui_long_connection(inputs, llm_kwargs, history, observe_window=ow)

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

Strategy: try-catch

Validate before calling

import time
assert len(observe_window) >= 2, 'watchdog contract requires heartbeat slot'
observe_window[1] = time.time()

Try / catch

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

Prevention

When it happens

Trigger: User cancels generation (feeder stops updating observe_window[1]); caller never starts a feeder thread; Volcano endpoint stalling >5s between yields while nobody refreshes the heartbeat.

Common situations: Gradio Stop during Skylark2 generation; plugin authors unaware of the two-element observe_window contract; network hiccup to Volcano cloud plus no feeder.

Related errors


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