Clojure program not exiting when finishing last statement?

后端 未结 2 2064
滥情空心
滥情空心 2021-01-17 09:53

What would cause a Clojure program to not immediately exit upon finishing the last statement in the main function?

All I did was to change a (doall (map ...))<

相关标签:
2条回答
  • 2021-01-17 10:09

    According to the docs:

    ...[pmap is O]nly useful for computationally intensive functions where the time of f dominates the coordination overhead.

    So this probably means there is more overhead using pmap for your scenario than using map. The pmap operations are probably taking a little extra time to finish up before the code after pmap fires.

    0 讨论(0)
  • 2021-01-17 10:16

    pmap will spin up multiple threads from a threadpool to service your concurrent tasks.

    Calling shutdown-agents is necessary to allow the JVM to exit in an orderly manner because the threads in the agent threadpools are not daemon threads.

    You need to explicitly tell them to gracefully shutdown (but only when your program is done). This looks to have been answered before here.

    Quoting from that answer:

    "You need to call shutdown-agents to kill the threads backing the threadpool used by pmap."

    Docs are here: http://clojuredocs.org/clojure_core/1.3.0/clojure.core/shutdown-agents

    0 讨论(0)
提交回复
热议问题