clojure.java.shell/sh throws RejectedExecutionException when run in a new thread
In a new fresh leiningen project, with its core.clj containing
(defn show-cmd
[]
(-> (shell/sh "ls")
:out
println))
(defn -main
[]
(.start (Thread. show-cmd)))
See https://gist.github.com/1183753 for the complete picture.
So, I get a RejectedExecutionException thrown when I do a lein run
on the above project. The complete stack trace is in the gist.
However, the above works just f开发者_如何转开发ine when put in a .clj
file and run directly with clojure, without leiningen in the workflow. Is this a bug in leiningen/clojure or is it just me?
If its a bug, please let me know how I can let the concerned know, as this would be the first time I've found a bug :)
Thanks.
Update Taking @skuro's suggestion, I tried my example with the master branch clone of leiningen, but I still get the same error, as illustrated here
This is a known problem with Leiningen which unfortunately won't be fixed soon. Fixing it would cause other stuff to break. The workaround is to force the main function to never return:
(defn -main
[]
(.start (Thread. show-cmd))
@(promise))
Here, since the promise is never fulfilled, main will wait forever, thus preventing Leiningen from shutting down the executors that run agents, futures, etc.
You need to upgrade to the latest and greatest leiningen version, possibly compiling from sources. There's a known bug with leiningen that prevents threads to be correctly executed. There are also other questions on the topic, a search might help.
I have seen this related to not being able to open standard input and error when run through leiningen. to work around it us i used
lein uberjar && java -jar projectstandalone.jar args.
it was w bit slower but worked
精彩评论