clojure - Why does this simple main method never return when run by leiningen? -
this piece of code returns immediately:
user=> (dorun (pmap + [1 2] [3 4])) nil
however, when run same piece of code in main method using lein:
(ns practice.core) (defn -main [& args] (dorun (pmap + [1 2] [3 4])))
why never return?
interestingly, if replace pmap
map
, returns normally.
you need call shutdown-agents
@ end of -main
method.
(defn -main [& args] (dorun (pmap + [1 2] [3 4])) (shutdown-agents))
this mentioned on http://clojure.org/agents:
note use of agents starts pool of non-daemon background threads prevent shutdown of jvm. use shutdown-agents terminate these threads , allow shutdown.
pmap
uses futures run on agent thread pool.
Comments
Post a Comment