0
votes

My problem is an unexpected situation with executing my clojure program.

I use Ubuntu 14.04 x64, Lein and Clojure(both last versions). I've finished my little project(web crawler, just for learning clojure). It works, I'm sure('cos I've run it in repl).

Ok, I'm trying to run it with lein in terminal (look at screenshot). It works correct, then prints elapsed time. But then, it's waiting for something. That's the problem. Program can't stop and can't give contol back to ubuntu's terminal. I've faced with it first time, all my projects before were complited by itself. Now the only way is "Ctrl + C". In code, I use "imperative" commands(doseq, do), file i/o (with-open reader/writer), agents(send-off, await) and "clj-http.client" for downloading webpages. They are the potential causes.

Here's my "main":

(defn crawl-bunch [depth]
  (do
    (send-off urls visit-urls)
    (await urls)
    (renew-urls)
    (await urls)
    (send-off urls mark-used-urls)
    (await urls)
    (dec depth)))

(defn crawl [depth]
  (loop [i depth]
    (if (= i 0)
      (save-found-urls "out_urls.txt")
      (recur (crawl-bunch i)))))

(defn -main [& args]
  (time 
   (do
    (file-to-urls "urls.txt")
    (crawl 1))))

Here's full source code - nearly 100 strings (/src/crawler/core.clj): https://github.com/ivanpetrov16130/crawler

Tell me please, how to fix it? Thank you for you answers and excuse me for grammatical, syntax and logical errors.

Image is full of sorrow."

1
zero323, It calls "crawl-bunch" function, which visits all the urls in "agent" and then returns decremented "i". My mistake, I should add this function to my question. - ivanpetrov16130
Try running shutdown-agents before exiting. - bsvingen
bsvingen, thank you, it works! So simple... - ivanpetrov16130
Great, I'll write it as an answer. - bsvingen
Accept bsvingen's answer if that solved your problem; no need to put an "update" in the question. - John Wiseman

1 Answers

2
votes

You need to run shutdown-agents in order for the thread pools used by the agents to shut down.