binary-husky/gpt_academic · error · RuntimeError

程序终止。

Error message

程序终止。

What it means

Watchdog of the Zhipu GLM streaming loop: during ZhipuChatInit.generate_chat iteration, if observe_window[1] is more than watch_dog_patience (5 s) in the past, the loop raises RuntimeError('程序终止。') and the worker thread stops.

Source

Thrown at request_llms/bridge_zhipu.py:43

    """
    watch_dog_patience = 5
    response = ""

    if llm_kwargs["llm_model"] == "zhipuai":
        llm_kwargs["llm_model"] = zhipuai_default_model

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

    # 开始接收回复
    from .com_zhipuglm import ZhipuChatInit
    zhipu_bro_init = ZhipuChatInit()
    for chunk, response in zhipu_bro_init.generate_chat(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:str, llm_kwargs:dict, plugin_kwargs:dict, chatbot:ChatBotWithCookies,
            history:list=[], system_prompt:str='', stream:bool=True, additional_fn:str=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)

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Retry the request; check Zhipu console for quota/usage errors
  2. Test streaming endpoint directly with curl to see whether chunks pause >5 s
  3. Raise watch_dog_patience if inter-chunk gaps are legitimately long
  4. Stabilize network / disable interfering proxies for open.bigmodel.cn

Example fix

# before
watch_dog_patience = 5

# after
watch_dog_patience = 30
Defensive patterns

Strategy: retry

Try / catch

try:
    ...
except RuntimeError as e:
    if str(e) == '程序终止。':
        logger.warning('zhipu stream stalled; retrying')
        return retry(inputs)
    raise

Prevention

When it happens

Trigger: ZhipuChatInit.generate_chat stops yielding for >5 s inside request_llms/bridge_zhipu.py:43 predict_no_ui_long_connection() — e.g. open.bigmodel.cn stream stall, 429 throttle, TLS/proxy interruption mid-stream.

Common situations: Free-tier Zhipu quota exhausted mid-stream causing a hang instead of clean error; network flakiness; GLM-4 long generations whose inter-chunk gap occasionally exceeds 5 s.

Related errors


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