dictionary-overlay
dictionary-overlay copied to clipboard
Got error: Cannot send message to a closed websocket
After installing the package and dependencies, I ran dictionary-overlay-start, I can see this in message buffer:
[WebsocketBridge] Server start websocket server on port 62124
When I invokedictionary-overlay-mark-buffer-unknown, it raised the error:
websocket-send-text: Cannot send message to a closed websocket
try run websocket-bridge-server-start restart the websocket server
Thanks, but that does not help, still got the same error.
This is strange, maybe try restarting emacs, try again.
1. environment
emacs 28.2, python3.8.2
2. config
(add-to-list 'load-path (expand-file-name "~/.emacs.d/customizations/my_plugins/dictionary-overlay/"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/customizations/my_plugins/websocket-bridge/"))
(use-package websocket-bridge
:commands (websocket-bridge-server-start))
(use-package dictionary-overlay
:commands (dictionary-overlay-start
dictionary-overlay-render-buffer)
:init
(setq dictionary-overlay-user-data-directory "~/.emacs.d/dictionary-overlay-data")
(setq dictionary-overlay-just-unknown-words nil))
3. problem
got the same error above! Try to restart the emacs, problem still.

(use-package dictionary-overlay :commands (dictionary-overlay-start dictionary-overlay-render-buffer)
don't run dictionary-overlay-render-buffer when load package.
just when you read english buffer, try to run dictionary-overlay-render-buffer
you could run (websocket-bridge-app-open-buffer 'dictionary-overlay) to check python run message.
Ok, finally got it working (with DoomEmacs).
Here's my config in case it's helpful to anyone..
in packages.el:
(package! websocket)
(package! websocket-bridge
:recipe (:host github :repo "ginqi7/websocket-bridge"))
(package! dictionary-overlay
:recipe (:host github :repo "ginqi7/dictionary-overlay"
:files (:defaults "*")))
in config.el:
(use-package! websocket
:defer t)
(use-package! websocket-bridge
:defer t)
(use-package! dictionary-overlay
:commands (dictionary-overlay-start))
遇到了同样的问题,没有解决方案啊?
@ginqi7 关于send to closed websocket 原因,我目前遇到的两类:
- 手速太快,D-O 服务器启动大约要1-3s时间,等待一下再render就好了
- dump不完整以致于dictionary.json不完整,发生错误。目前的dump机制出问题几率挺大的,以致于dictionary.json文件经常只dump一部分,使得括号unbalanced。我这个json文件现在有2.2mb,总是坏,基本规律是文件越大,坏的可能性越大,几分钟就坏一次,文件能长到2.2m全靠dropbox续命。我前天把dump机制恢复到以前(只有三行那个版本),目前使用dump一切正常。我觉得一些莫名其妙的send to closed socket是dump原因导致的,可以试试退到以前?
那干脆revert 这次提交好了。e563d514d38b1aaa33ca48204b2c259fb9e249e5
原本是为了可以手动修改 =dictionary.json= 文件,但看来这种方式不合适。
是的,考虑复杂了。😄 On Feb 19, 2023, 01:30 -0500, ginqi7 @.***>, wrote:
那干脆revert 这次提交好了。e563d514d38b1aaa33ca48204b2c259fb9e249e5 原本是为了可以手动修改 =dictionary.json= 文件,但看来这种方式不合适。 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
@qingshuizheng 回退了,大佬词典内容比较多。有空帮忙测试一下。现在ov运行期间无法手动修改dictionary.json 文件了。
@czqhurricnae 麻烦更新到最新版本。然后对照 @qingshuizheng 的建议,看看你的报错是出现在哪一步。 由于ov 异步启动需要时间。推荐把(dictionary-overlay-start) 放在 init 文件里。当Emacs 启动时,让ov默默启动。 然后阅读英文文章时,运行 dictionary-overlay-render-buffer 渲染当前buffer。
坚持需要这个文件的完整性是因为一些专有词汇只能靠自己积累。本地积累一些,渲染飞快。
我自己本地回退有一段时间了,还是很靠谱的。
感谢大佬! On Feb 19, 2023, 21:17 -0500, ginqi7 @.***>, wrote:
@qingshuizheng 回退了,大佬词典内容比较多。有空帮忙测试一下。现在ov运行期间无法手动修改dictionary.json 文件了。 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
@ginqi7 let: Symbol’s value as variable is void: websocket-bridge-client-dictionary-overlay
@ginqi7
let: Symbol’s value as variable is void: websocket-bridge-client-dictionary-overlay
麻烦问一下,你的配置是怎样的?你是如果使用时报错的?
@ginqi7 我搜索了本地 dictionary-overlay 文件夹,包含
(defun dictionary-overlay-ready-p ()
"Check diction-overly if ready."
(and
(member "dictionary-overlay" websocket-bridge-app-list)
(boundp 'websocket-bridge-client-dictionary-overlay)))
只有该处提及该变量,可能是你的自己配置有这个变量吧,没有写到包里?
应该不是,websocket-bridge-client-dictionary-overlay 是在 websocket-bridge 那个包里定义的。报错也应该是那边触发的。(boundp 'any-symbol) boundp 任何符号应该都不会报错,只会返回null才对。

websocket-bridge 也没有该变量定义。
先启动(dictionary-overlay-start) 然后运行(websocket-bridge-app-log-buffer) 查看日志。我猜测是因为 python 包没有安装完全,导致dictionary-overlay没有启动成功。
@ginqi7 我也遇到了无法解决的 “websocket-bridge-client-dictionary-overlay”问题,回退到我之前自己正常工作的分支也还是有这个问题。
跑了一下 (websocket-bridge-app-log-buffer) ->
Traceback (most recent call last):
File "/Users/z/.emacs.d/lib/dictionary-overlay/dictionary-overlay.py", line 10, in <module>
import snowballstemmer
ModuleNotFoundError: No module named 'snowballstemmer'
检查了下路径,没有错。是因为 python 的环境变了么?我最近跑了一次 homebrew cleanup --prune-all, 不知道是不是因为这个原因。
@qingshuizheng 估计是python 的环境变了吧。重新装一下python包应该就可以了:(dictionary-overlay-install)
@czqhurricnae 你这边遇到的估计也是类似的问题,看看日志里是不是某个 python 包没有装。
@qingshuizheng 估计是python 的环境变了吧。重新装一下python包应该就可以了:(dictionary-overlay-install)
多谢,我发现 dictionary-overlay-install 后 snowballstemmer 安装到 python 3.11 目录下了,但我 M-x run-python RET 里的版本却是 3.8.9,所以找不到snowballstemmer。我猜是这个原因,但不知道怎么改(抚额
@qingshuizheng 可以设定 Emacs 变量 dictionary-overlay-python 为完整的 python 路径,指定到 3.11 的那个 python。 或者用 3.8.9 的 python 路径下的pip,手动 pip install snowballstemmer。
@ginqi7 嗯应该是这个问题了,后面几天都在路上,暂时没时间调整了。感谢!
我也遇到了类似的问题,发现错误在sdcv的设置问题。 (setq dictionary-overlay-sdcv-dictionary-path "~/.../resource/kdic-ec-11w"), sdcv的词典后缀不能加。否则报错。