Why is this simple main method never returned when leiningen starts?

This piece of code returns immediately:

user=> (dorun (pmap + [1 2] [3 4])) nil 

However, when I run the same piece of code in the main method using lein:

 (ns practice.core) (defn -main [& args] (dorun (pmap + [1 2] [3 4]))) 

why is he never coming back?

Interestingly, if I replaced pmap with map , it returns normally.

+7
source share
1 answer

You need to call shutdown-agents at the end of your -main method.

 (defn -main [& args] (dorun (pmap + [1 2] [3 4])) (shutdown-agents)) 

This is stated at http://clojure.org/agents :

Note that using agents starts the non-daemon pool of background threads, which will prevent the JVM from stopping. Use shutdown tools to stop these threads and enable shutdown.

pmap uses futures that run in the agent thread pool.

+9
source

All Articles