Additional delay after pcalls?

2011-07-27 Thread mc4924
Hello everyone, I am a beginner with clojure and I am playing around
with pcalls (I am using clojure 1.2.1).
I see different behavior if I run some code from inside the REPL or
launching it form the command line.

I have the following code in a file called test-pcalls.clj:

(let [waste-time (fn [label]
(dotimes [k 4]
  (let [msg (str label   k \n)]
(Thread/sleep 2000)
(print msg]
  (dorun (pcalls #(waste-time A) #(waste-time b

This just creates the function 'waste-time' which slowly (2 seconds at
a time) counts 0..3 and prints a label and the count each time. Two
copies of the function are then started in parallel with a different
label (A and b)

I start clojure and then from the REPL I do (load-file test-
pcalls.clj).
After 8 seconds (2 seconds x 4) I see the two sequences being printed
out all in one go.
First question I cannot find an aswer is: why do I see everything
printed together instead of one step a time?

Then I exit to the command line and then start clojure with the source
file:
   clojure test-pcalls.clj
Again after 8 seconds I see the sequences printed out as above. But
now clojure hangs for a minute or so before returning to the command
prompt.
Can anyone explain this additional delay?

thanks

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Additional delay after pcalls?

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 11:44 AM, mc4924 claudio.potenza...@gmail.com wrote:
 Hello everyone, I am a beginner with clojure and I am playing around
 with pcalls (I am using clojure 1.2.1).
 I see different behavior if I run some code from inside the REPL or
 launching it form the command line.

 I have the following code in a file called test-pcalls.clj:

 (let [waste-time (fn [label]
                    (dotimes [k 4]
                      (let [msg (str label   k \n)]
                        (Thread/sleep 2000)
                        (print msg]
  (dorun (pcalls #(waste-time A) #(waste-time b

 This just creates the function 'waste-time' which slowly (2 seconds at
 a time) counts 0..3 and prints a label and the count each time. Two
 copies of the function are then started in parallel with a different
 label (A and b)

 I start clojure and then from the REPL I do (load-file test-
 pcalls.clj).
 After 8 seconds (2 seconds x 4) I see the two sequences being printed
 out all in one go.
 First question I cannot find an aswer is: why do I see everything
 printed together instead of one step a time?

Buffering of I/O. Try using println, or adding (.flush *out*) after each print.

 Then I exit to the command line and then start clojure with the source
 file:
   clojure test-pcalls.clj
 Again after 8 seconds I see the sequences printed out as above. But
 now clojure hangs for a minute or so before returning to the command
 prompt.
 Can anyone explain this additional delay?

Waiting for the pcalls thread pool to shut down, I expect.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Additional delay after pcalls?

2011-07-27 Thread Ben Mabey

On 7/27/11 11:19 AM, Ken Wesson wrote:

On Wed, Jul 27, 2011 at 11:44 AM, mc4924claudio.potenza...@gmail.com  wrote:

Hello everyone, I am a beginner with clojure and I am playing around
with pcalls (I am using clojure 1.2.1).
I see different behavior if I run some code from inside the REPL or
launching it form the command line.

I have the following code in a file called test-pcalls.clj:

(let [waste-time (fn [label]
(dotimes [k 4]
  (let [msg (str label   k \n)]
(Thread/sleep 2000)
(print msg]
  (dorun (pcalls #(waste-time A) #(waste-time b

This just creates the function 'waste-time' which slowly (2 seconds at
a time) counts 0..3 and prints a label and the count each time. Two
copies of the function are then started in parallel with a different
label (A and b)

I start clojure and then from the REPL I do (load-file test-
pcalls.clj).
After 8 seconds (2 seconds x 4) I see the two sequences being printed
out all in one go.
First question I cannot find an aswer is: why do I see everything
printed together instead of one step a time?

Buffering of I/O. Try using println, or adding (.flush *out*) after each print.


Then I exit to the command line and then start clojure with the source
file:
   clojure test-pcalls.clj
Again after 8 seconds I see the sequences printed out as above. But
now clojure hangs for a minute or so before returning to the command
prompt.
Can anyone explain this additional delay?

Waiting for the pcalls thread pool to shut down, I expect.

Yeah, you will want to call '(shutdown-agents)' to have Clojure shut 
down the thread pool it uses for agents, futures, etc..


-Ben

--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en