binary-husky/gpt_academic · error · RuntimeError

程序终止。

Error message

程序终止。

What it means

Watchdog RuntimeError('程序终止。') in bridge_qwen.predict_no_ui_long_connection: while draining QwenRequestInstance.generate, observe_window[1] (heartbeat timestamp) aged past watch_dog_patience (5s), so the loop aborts. It mirrors the cancellation contract of all other bridges - the Qwen dashscope/Tongyi stream itself rarely stalls this long, so the usual cause is the caller no longer feeding the dog.

Source

Thrown at request_llms/bridge_qwen.py:23

model_name = 'Qwen'

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

    from .com_qwenapi import QwenRequestInstance
    sri = QwenRequestInstance()
    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(["dashscope"])
    except:
        yield from update_ui_latest_msg(f"导入软件依赖失败。使用该模型需要额外依赖,安装方法```pip install --upgrade dashscope```。",
                                         chatbot=chatbot, history=history, delay=0)
        return

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. If user-cancelled: expected behavior, handle cleanup and return
  2. Run a feeder thread updating observe_window[1] every 1-2 seconds for the duration you want output
  3. Increase watch_dog_patience if Qwen cold-start latency regularly exceeds 5s
  4. Wrap the call in try/except RuntimeError to separate cancellation from API errors

Example fix

# before
ow = [partial, time.time()]  # timestamp set once

# after
import threading, time
stop = threading.Event()
def feed():
    while not stop.is_set():
        ow[1] = time.time(); time.sleep(1)
threading.Thread(target=feed, daemon=True).start()
Defensive patterns

Strategy: try-catch

Validate before calling

import time
assert len(observe_window) >= 2
observe_window[1] = time.time()  # prime heartbeat before first chunk

Try / catch

try:
    result = predict_no_ui_long_connection(inputs, llm_kwargs, history, sys_prompt, observe_window=ow)
except RuntimeError as e:
    if str(e) == '程序终止。':
        handle_user_cancel(ow[0])
        return
    raise

Prevention

When it happens

Trigger: Caller stops refreshing observe_window[1] (Stop button, dead feeder thread); dashscope stream hangs >5s with no yield and the feeder was never started; pausing in a debugger.

Common situations: User cancels a Qwen generation in the WebUI; plugin reuses predict_no_ui_long_connection but omits the heartbeat thread; long first-token latency on Qwen API plus tight patience.

Related errors


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