Skip to main content
 首页 » 编程设计

common-lisp之从 Emacs 多线程错误保存 SBCL 图像

2024年02月05日30thcjp

我一直在尝试保存正在运行的 Common Lisp 图像,以节省重新启动时的时间并提高开发效率。然而,当我在 Emacs/SLIME 中运行以下命令时,我遇到了一些问题:

(sb-ext:save-lisp-and-die "rest-api-image" :purify t) 

我收到以下错误。显然,它提示看到多个线程。据我所知,这些不是我以编程方式创建的线程。相反,它们是 Lisp 和 Emacs 创建的。这里有解决方法吗?图片还能保存吗?

Cannot save core with multiple threads running. 
 
Interactive thread (of current session): 
  #<THREAD "main thread" RUNNING {1000550853}> 
 
Other threads: 
  #<THREAD "Swank Sentinel" #1=waiting on: 
       #<WAITQUEUE  {1004AB8003}> 
     {1004AB4753}>, 
  #<THREAD "control-thread" #1# 
       #<WAITQUEUE  {1005BC54D3}> 
     {1004D87F03}>, 
  #<THREAD "reader-thread" RUNNING {1004D88063}>, 
  #<THREAD "swank-indentation-cache-thread" #1# 
       #<WAITQUEUE  {1004D980E3}> 
     {1004D88183}>, 
  #<THREAD "auto-flush-thread" RUNNING {10022FFDA3}>, 
  #<THREAD "repl-thread" RUNNING {1002300003}> 
   [Condition of type SB-IMPL::SAVE-WITH-MULTIPLE-THREADS-ERROR] 
See also: 
  SBCL Manual, Saving a Core Image [:node] 

请您参考如下方法:

这本食谱已为您介绍:https://lispcookbook.github.io/cl-cookbook/scripting.html

涉及的步骤是:

(load "my-app.asd") 
(ql:quickload :my-app) 
(sb-ext:save-lisp-and-die #p"my-app-binary" :toplevel #'my-app:main :executable t) 

这就是可能的 Makefile 目标:

build: 
    sbcl --load my-app.asd \ 
         --eval '(ql:quickload :my-app)' \ 
         --eval "(sb-ext:save-lisp-and-die #p\"my-app\" :toplevel #my-app:main :executable t)" 

但使用 asdf 这样做是可移植的。将其添加到您的 .asdf 系统定义中:

:build-operation "program-op" ;; leave as is 
:build-pathname "<binary-name>" 
:entry-point "<my-package:main-function>" 

然后

(asdf:make :my-package) 

构建一个网络应用程序及其网络服务器,又是一个步骤。

要解析命令行参数,请捕获 C-c,将所有内容放在 CI 上,请参阅 Cookbook!

ps:如果您需要在裸 sbcl repl 中进行尝试,请查看 cl-repl ,甚至 sbcli ,它们比 rlwrap sbcl 更好。