从今天开始,Emacs里面可以运行任何你想要的程序 (Linux & Windows & Mac & BSD)

是不是用 pip 安装的 pyqt5 ?

忘记说了,是Windows系统

pyqt5是以前装eaf的时候装上的,我把它卸掉之后重新用 install-eaf.py 安装,现在eaf直接启动不了了?

Traceback (most recent call last):
  File "c:\Users\xxx\AppData\Roaming\.emacs.d\elisp\emacs-application-framework\eaf.py", line 25, in <module>
    from PyQt5 import QtWebEngineWidgets as NeverUsed # noqa
ImportError: DLL load failed while importing QtWebEngineWidgets: 找不到指定的模块。

我不用windows,抱歉帮不了你

exited abnormally with code 9,这个编号的意义在哪可以看到?

9应该是seg fault吧?

你的pyqtwebenging没装对。

EAF最近加了很多多语言互调用API,补了一下文档 Emacs指尖的魔法

2 个赞

eaf-terminal 报这种错有什么解决办法嘛

系统是manjaro,我之前改了hostname,看网上一些回答好像是改hostname导致的

_IceTransSocketUNIXConnect: Cannot connect to non-local host manjaro
_IceTransSocketUNIXConnect: Cannot connect to non-local host manjaro
Qt: Session management error: Could not open network socket
127.0.0.1 - - [14/Sep/2021 13:56:36] "GET /index.html HTTP/1.1" 200 -
Session is not restored, as no data present in session file.
127.0.0.1 - - [14/Sep/2021 13:56:36] "GET /node_modules/xterm-addon-fit/lib/xterm-addon-fit.js HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2021 13:56:36] "GET /node_modules/xterm/css/xterm.css HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2021 13:56:36] "GET /node_modules/xterm/lib/xterm.js HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2021 13:56:36] "GET /node_modules/xterm-addon-attach/lib/xterm-addon-attach.js HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2021 13:56:36] "GET /node_modules/xterm-addon-search/lib/xterm-addon-search.js HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2021 13:56:36] "GET /node_modules/xterm-addon-web-links/lib/xterm-addon-web-links.js HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2021 13:56:36] "GET /dark_theme.js HTTP/1.1" 200 -
WebSocket connection to 'ws://127.0.0.1:40237/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

hostname 改回manjaro,报错变成了这样

Qt: Session management error: Could not open network socket
127.0.0.1 - - [14/Sep/2021 14:04:46] "GET /index.html HTTP/1.1" 200 -
Session is not restored, as no data present in session file.
127.0.0.1 - - [14/Sep/2021 14:04:46] "GET /node_modules/xterm-addon-attach/lib/xterm-addon-attach.js HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2021 14:04:46] "GET /node_modules/xterm/css/xterm.css HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2021 14:04:46] "GET /dark_theme.js HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2021 14:04:46] "GET /node_modules/xterm/lib/xterm.js HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2021 14:04:46] "GET /node_modules/xterm-addon-fit/lib/xterm-addon-fit.js HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2021 14:04:46] "GET /node_modules/xterm-addon-search/lib/xterm-addon-search.js HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2021 14:04:46] "GET /node_modules/xterm-addon-web-links/lib/xterm-addon-web-links.js HTTP/1.1" 200 -
WebSocket connection to 'ws://127.0.0.1:41115/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
Qt: Session management error: Could not open network socket

你重新在终端目录里面 npm build 一下看看。

重新在 terminal 目录下 npm install 仍然会报下面的错

Qt: Session management error: Could not open network socket
127.0.0.1 - - [15/Sep/2021 10:50:54] "GET /index.html HTTP/1.1" 200 -
Session is not restored, as no data present in session file.
127.0.0.1 - - [15/Sep/2021 10:50:54] "GET /node_modules/xterm/css/xterm.css HTTP/1.1" 200 -
127.0.0.1 - - [15/Sep/2021 10:50:54] "GET /node_modules/xterm-addon-web-links/lib/xterm-addon-web-links.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Sep/2021 10:50:54] "GET /dark_theme.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Sep/2021 10:50:54] "GET /node_modules/xterm/lib/xterm.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Sep/2021 10:50:54] "GET /node_modules/xterm-addon-attach/lib/xterm-addon-attach.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Sep/2021 10:50:54] "GET /node_modules/xterm-addon-fit/lib/xterm-addon-fit.js HTTP/1.1" 200 -
127.0.0.1 - - [15/Sep/2021 10:50:54] "GET /node_modules/xterm-addon-search/lib/xterm-addon-search.js HTTP/1.1" 200 -
WebSocket connection to 'ws://127.0.0.1:35307/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
Qt: Session management error: Could not open network socket

执行 npm rebuild

还是一样的报错 :joy:

你可以终端手动启动 node sever , 看看有啥输出。

怎么启动 sever ,buffer.py 代码里有,需要折腾下

在 terminal 下执行下面的python 代码,没有任何输出

import socket
import subprocess

def get_free_port():
    """
    Determines a free port using sockets.
    """
    free_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    free_socket.bind(('0.0.0.0', 0))
    free_socket.listen(5)
    port = free_socket.getsockname()[1]
    free_socket.close()

    return port

port = get_free_port()
server_js = "server.js"
start_directory = "."
command = "/usr/bin/zsh"
args = ["node", server_js, str(port), start_directory, command]

process = subprocess.Popen(
    args,
    stdout=subprocess.PIPE,
    stderr=subprocess.STDOUT,
    shell=False)

outs, errs = process.communicate()
print(outs, errs)

@manateelazycat 大佬,我这边eaf browser 挂了,报的错

Qt WebEngine resources not found at /share/qt/resources. Trying parent directory...
Qt WebEngine resources not found at /share/qt. Trying application directory...
Qt WebEngine resources not found at /usr/bin. Trying fallback directory... The application MAY NOT work.

已经更新eaf,并运行install-eaf.py。能帮我看看吗?

你的pyqt挂了吧?重装一下pyqt?

运行install-eaf.py会重装所有依赖。没效果啊。

我用的是manjaro xfce,不知道是怎么回事就挂了。试了一些网上的方法也没解决。我再看看吧。 :handshake:

更新: 问题解决了。应该是qtwebengine的bug。这导致启动的时候找不到qtwebengine_resources*.pak文件,然后就挂了。现在临时手工做个软链修复一下路径。 ln -s /usr/share/qt/resources ~/.eaf.py 等后面包更新看会不会修复。

EAF 多线程编程模型

中科院举办的 “2021中国开源之夏”,今年EAF社区持续参与,今天在辅导同学编写新闻阅读器的过程中,同学提到了:怎么用多线程来实现后台刷新新闻数据?

简单整理了一下EAF怎么实现多线程的编程模型,为了方便实践,建议参考 EAF file-manager buffer.py 里的GitCommitThread代码实现:

  1. QThread的原理很简单,首先创建一个 QThread 的类,然后把耗时代码丢到 run 函数中
  2. 在主线程(EAF就是AppBuffer的函数)创建 QThread 的实例,为了避免调用函数作用域跳出导致 QThread 实例被销毁,可以把 QThread 实例加到一个队列对象中以保持引用 (具体参考 file-manager 的队列对象 fetch_git_log_threads)
  3. QThread创建好以后,直接调用 thread.start() 会在一个子线程运行耗时代码
  4. 图形编程中要遵守 “子线程不能直接操作图形界面,只有主线程可以操作图形界面” 的原则,QThread中run函数完成耗时操作后,需要通过发送信号到主线程来提醒主线程刷新界面 (参考 GitCommitThread 的 fetch_command_result 信号)
  5. 主线程接收到 QThread 的完成信号,调用图形代码刷新界面,为了遵守步骤4中的原则,刷新界面的回调函数需要用装饰器 @PostGui() 包装一下,保证操作界面代码只运行在主线程中 (具体参考 file-manager 的 update_git_log 函数)

以上就是EAF中实现多线程的全部关键步骤,此原理也适用于任何Qt程序。

9 个赞

昨天手贱升级了arch,然后eaf browser就用不了了。疑似是依赖出bug了?麻烦大佬瞅一眼 :smile:

*eaf* 一直报这个错

[603115:603115:0930/102450.772260:ERROR:network_service_instance_impl.cc(286)] Network service crashed, restarting service.
[603115:603115:0930/102451.247758:ERROR:network_service_instance_impl.cc(286)] Network service crashed, restarting service.

我在这个commit 3249880aae8353524ad5f785101bbcc8a48b5e4e


这是目前依赖版本

@manateelazycat file-manage现在是依赖doom-modeline吗?如果不启用doom-modeline会报voild variable doom-modeline-mode的错,但是再次调用eaf-open-file-manage还是能打开file-manage。

Debugger entered--Lisp error: (void-variable doom-modeline-mode)
  (and doom-modeline-mode doom-modeline-icon doom-modeline-major-mode-icon)
  (if (and doom-modeline-mode doom-modeline-icon doom-modeline-major-mode-icon) (progn (set (make-local-variable 'doom-modeline--buffer-file-icon) (eaf-all-the-icons-icon mode-name))))
  eaf-all-the-icons-update-icon()
  (progn nil (eaf-all-the-icons-update-icon))
  (if (and (condition-case nil (progn (require 'all-the-icons) (featurep 'eaf-all-the-icons)) (error nil))) (progn nil (eaf-all-the-icons-update-icon)))
  eaf--update-modeline-icon()
  (save-current-buffer (set-buffer buffer) (eaf-call-async "new_buffer" eaf--buffer-id (if (eaf--called-from-wsl-on-windows-p) (eaf--translate-wsl-url-to-windows url) url) (eaf--get-app-module-path app-name) args) (eaf--update-modeline-icon))
  (let* ((buffer (eaf--create-buffer url app-name args))) (save-current-buffer (set-buffer buffer) (eaf-call-async "new_buffer" eaf--buffer-id (if (eaf--called-from-wsl-on-windows-p) (eaf--translate-wsl-url-to-windows url) url) (eaf--get-app-module-path app-name) args) (eaf--update-modeline-icon)) (eaf--preview-display-buffer app-name buffer))
  eaf--open-internal("~" "file-manager" "")
  (if (and exists-eaf-buffer (not always-new)) (progn (eaf--preview-display-buffer app-name exists-eaf-buffer) (message (concat "[EAF/" app-name "] " "Switch to %s") url)) (eaf--open-internal url app-name args) (message (concat "[EAF/" app-name "] " "Opening %s") url))
  (let (exists-eaf-buffer) (catch 'found-eaf (let ((--dolist-tail-- (eaf--get-eaf-buffers))) (while --dolist-tail-- (let ((buffer (car --dolist-tail--))) (save-current-buffer (set-buffer buffer) (if (and ... ...) (progn ... ...))) (setq --dolist-tail-- (cdr --dolist-tail--)))))) (if (and exists-eaf-buffer (not always-new)) (progn (eaf--preview-display-buffer app-name exists-eaf-buffer) (message (concat "[EAF/" app-name "] " "Switch to %s") url)) (eaf--open-internal url app-name args) (message (concat "[EAF/" app-name "] " "Opening %s") url)))
  (if (eaf-epc-live-p eaf-epc-process) (let (exists-eaf-buffer) (catch 'found-eaf (let ((--dolist-tail-- (eaf--get-eaf-buffers))) (while --dolist-tail-- (let ((buffer ...)) (save-current-buffer (set-buffer buffer) (if ... ...)) (setq --dolist-tail-- (cdr --dolist-tail--)))))) (if (and exists-eaf-buffer (not always-new)) (progn (eaf--preview-display-buffer app-name exists-eaf-buffer) (message (concat "[EAF/" app-name "] " "Switch to %s") url)) (eaf--open-internal url app-name args) (message (concat "[EAF/" app-name "] " "Opening %s") url))) (if eaf--first-start-app-buffers nil (setq eaf--first-start-app-buffers (cons (list url app-name args) eaf--first-start-app-buffers))) (eaf-start-process) (message (concat "[EAF/" app-name "] " "Opening %s") url))
  eaf-open("~" "file-manager")
  eaf-open-file-manager()
  funcall-interactively(eaf-open-file-manager)
  call-interactively(eaf-open-file-manager)