当使用“lein run”运行时,关闭挂钩不触发。

编程入门 行业动态 更新时间:2024-10-28 07:28:34
本文介绍了当使用“lein run”运行时,关闭挂钩不触发。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下代码:

(ns test-hook.core) (defn -main [] (.addShutdownHook(Runtime / getRuntime)(Thread。#(printlnshutdown)))(printlnstart) (doseq [i(range 1 6)] (Thread / sleep 1000)(println i)))

和以下project.clj

(defproject test- hook1.0.0-SNAPSHOT:aot:all :main test-hook.core :descriptionFIXME:write description:dependencies [[org.clojure / clojure1.2.0]])

当我运行lein run钩子仅在正常程序执行时执行,而不是在接收SIGINT(Ctrl-C)

时运行相同的代码,在lein外部成功执行关闭钩子,即使接收到SIGINT 。

如何使用Ctrl-C运行时执行关闭挂接?

lein trampoline run

似乎适合我。

AFAIKlein trampoline不嵌套JVM,因此您的Ctrl-C不会被leiningen捕获,而是由您的代码捕获。

I have the following code:

(ns test-hook.core) (defn -main [] (.addShutdownHook (Runtime/getRuntime) (Thread. #(println "shutdown"))) (println "start") (doseq [i (range 1 6)] (Thread/sleep 1000) (println i)))

and the following project.clj

(defproject test-hook "1.0.0-SNAPSHOT" :aot :all :main test-hook.core :description "FIXME: write description" :dependencies [[org.clojure/clojure "1.2.0"]])

when I run it with "lein run" the shutdown hook only gets executed on normal program execution, not when receiving SIGINT (Ctrl-C)

the same code when ran outside of lein successfully executes the shutdown hook even when receiving SIGINT.

how can I have the shutdown hook executed when running from lein and aborting with Ctrl-C?

解决方案

Have you tried running it with trampoline?

lein trampoline run

Seems to work for me.

AFAIK "lein trampoline" doesn't nest the JVM, so your Ctrl-C isn't caught by leiningen, but by your code.

更多推荐

当使用“lein run”运行时,关闭挂钩不触发。

本文发布于:2023-10-13 14:35:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1488227.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:lein   run

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!