binary-husky/gpt_academic · error · RuntimeError
用户取消了程序。
Error message
用户取消了程序。
What it means
RuntimeError ('用户取消了程序。') from the Cohere bridge's watchdog in predict_no_ui_long_connection. While consuming Cohere's SSE events (text-generation frames appended to result), the code checks observe_window[1] — a timestamp the UI thread refreshes — against watch_dog_patience (5 s). If new text arrives but the timestamp is stale, the loop aborts on the assumption the user cancelled or the UI died. Standard cooperative-cancellation mechanism replicated across all bridges.
Source
Thrown at request_llms/bridge_cohere.py:122
while True:
try: chunk = next(stream_response)
except StopIteration:
break
except requests.exceptions.ConnectionError:
chunk = next(stream_response) # 失败了,重试一次?再失败就没办法了。
chunk_decoded, chunkjson, has_choices, choice_valid, has_content, has_role = decode_chunk(chunk)
if chunkjson['event_type'] == 'stream-start': continue
if chunkjson['event_type'] == 'text-generation':
result += chunkjson["text"]
if not console_silence: print(chunkjson["text"], end='')
if observe_window is not None:
# 观测窗,把已经获取的数据显示出去
if len(observe_window) >= 1:
observe_window[0] += chunkjson["text"]
# 看门狗,如果超过期限没有喂狗,则终止
if len(observe_window) >= 2:
if (time.time()-observe_window[1]) > watch_dog_patience:
raise RuntimeError("用户取消了程序。")
if chunkjson['event_type'] == 'stream-end': break
return result
def predict(inputs:str, llm_kwargs:dict, plugin_kwargs:dict, chatbot:ChatBotWithCookies,
history:list=[], system_prompt:str='', stream:bool=True, additional_fn:str=None):
"""
发送至chatGPT,流式获取输出。
用于基础的对话功能。
inputs 是本次问询的输入
top_p, temperature是chatGPT的内部调优参数
history 是之前的对话列表(注意无论是inputs还是history,内容太长了都会触发token数量溢出的错误)
chatbot 为WebUI中显示的对话列表,修改它,然后yield出去,可以直接修改对话界面内容
additional_fn代表点击的哪个按钮,按钮见functional.py
"""
# if is_any_api_key(inputs):
# chatbot._cookies['api_key'] = inputs
# chatbot.append(("输入已识别为Cohere的api_key", what_keys(inputs)))View on GitHub (pinned to d6bde0fa54)
Solutions
- If deliberate, re-send the query after stopping.
- Keep the UI tab in the foreground during generation.
- Custom callers: update observe_window[1] = time.time() at ~1 Hz for the duration of the stream.
- Raise watch_dog_patience in request_llms/bridge_cohere.py for slow setups.
Defensive patterns
Strategy: validation
Try / catch
try:
result = predict_no_ui_long_connection(inputs, llm_kwargs, history, sys_prompt, observe_window=win)
except RuntimeError as e:
if '用户取消了程序' in str(e):
handle_cancel_or_stale_watchdog()
else:
raise Prevention
- Feed observe_window[1] at ~1 Hz from a live thread during the whole Cohere stream.
- Tear down the feeder when the request finishes.
- Keep the UI tab responsive; suspended tabs stop feeding the watchdog.
- Raise the patience constant for slow Cohere relays.
When it happens
Trigger: User stops generation in the Gradio UI during a Cohere response; UI polling thread stops updating observe_window[1] (suspended tab, stalled Gradio queue); custom integration passes observe_window without a feeding thread while text-generation events stream in.
Common situations: Intentional stops mid-answer; slow Cohere API or relay causing UI thread starvation; backgrounded browser tabs freezing the watchdog feed.
Related errors
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/674da743c1e3869f.
Report an issue: GitHub.