Re: core.async/thread failing silently

2013-12-08 Thread Paul Butcher
On 8 Dec 2013, at 05:04, Alex Miller a...@puredanger.com wrote:

 Errors are most likely occurring on a thread different than main. Assuming 
 you're using nrepl, have you looked at the nrepl-error buffer?

Thanks. I wasn't aware of nrepl-error. Some quick googling has turned up a few 
articles about how to see nrepl-error when using emacs, but I'm afraid that I'm 
not - I'm starting nREPL with lein repl at the bash prompt. I'd be grateful 
for any pointers to how to view nrepl-error in this scenario.

Thanks,

--
paul.butcher-msgCount++

Silverstone, Brands Hatch, Donington Park...
Who says I have a one track mind?

http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
Skype: paulrabutcher

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: core.async/thread failing silently

2013-12-08 Thread Alex Miller
If you're starting with lein repl then I would expect errors to be printed at 
the console - that's the actual process running the code. It's also possible 
that the thread's untaught exception handler doesn't print. I know that the 
expectation for async go blocks is that you should catch and handle any error. 
Have tried catching Throwable in your thread block and printing?

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: core.async/thread failing silently

2013-12-08 Thread Paul Butcher
On 8 Dec 2013, at 14:21, Alex Miller a...@puredanger.com wrote:

 If you're starting with lein repl then I would expect errors to be printed at 
 the console - that's the actual process running the code. It's also possible 
 that the thread's untaught exception handler doesn't print. I know that the 
 expectation for async go blocks is that you should catch and handle any 
 error. Have tried catching Throwable in your thread block and printing?

Yup - that works fine (see below).

The implication, I guess, is that nrepl doesn't set the default uncaught 
exception handler? I find that surprising?

user= (require '[clojure.core.async :refer [thread !!]])
nil
user= (defn thread-add [x y]
  #_=   (thread
  #_= (try
  #_=   (if (zero? y)
  #_= x
  #_= (let [t (thread-add (inc x) (dec y))]
  #_=   (!! t)))
  #_=   (catch Throwable e (println e)
#'user/thread-add
user= (!! (thread-add 10 10))
20
user= (!! (thread-add 10 2000))
Exception in thread async-thread-macro-1986 java.lang.OutOfMemoryError: 
unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:691)
at 
java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:943)
at 
java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.java:992)
at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

--
paul.butcher-msgCount++

Silverstone, Brands Hatch, Donington Park...
Who says I have a one track mind?

http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
Skype: paulrabutcher




On 8 Dec 2013, at 14:21, Alex Miller a...@puredanger.com wrote:

 If you're starting with lein repl then I would expect errors to be printed at 
 the console - that's the actual process running the code. It's also possible 
 that the thread's untaught exception handler doesn't print. I know that the 
 expectation for async go blocks is that you should catch and handle any 
 error. Have tried catching Throwable in your thread block and printing?
 
 -- 
 -- 
 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
 --- 
 You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: core.async/thread failing silently

2013-12-08 Thread Colin Jones
I've run this a bunch of times (in BOTH `lein repl` and `java -cp [...] 
clojure.main`), and have observed both this code printing the OOM 
exception, and it being silent as you observed. 

The difference in trials *seems* to be that if I skip the intermediate 
steps, going straight for the big one - (!! (thread-add 10 2000)) - then I 
get the exception printed: Exception in thread async-thread-macro-1999 
java.lang.OutOfMemoryError: unable to create new native thread. Whereas if 
I do this first - (!! (thread-add 10 1000)) - then I get the silent error 
as you are seeing. This seems pretty repeatable, but I don't really 
understand.

It looks like Exceptions (Throwables, really) will never propagate from the 
executor that `thread-call` calls, since they're swallowed in core.async: 
https://github.com/clojure/core.async/blob/ae37883a10dc9249ac5f204f6900e7bb0dbe1e04/src/main/clojure/clojure/core/async.clj#L381-L382

Maybe whether the error prints or not depends on whether the exception gets 
raised on the receiving side (the main thread) or the sending side 
(presumably on an Executor)?




On Sunday, December 8, 2013 9:27:44 AM UTC-6, Paul Butcher wrote:

 On 8 Dec 2013, at 14:21, Alex Miller al...@puredanger.com javascript: 
 wrote:

 If you're starting with lein repl then I would expect errors to be printed 
 at the console - that's the actual process running the code. It's also 
 possible that the thread's untaught exception handler doesn't print. I know 
 that the expectation for async go blocks is that you should catch and 
 handle any error. Have tried catching Throwable in your thread block and 
 printing?


 Yup - that works fine (see below).

 The implication, I guess, is that nrepl doesn't set the default uncaught 
 exception handler? I find that surprising?

 user= (require '[clojure.core.async :refer [thread !!]])
 nil
 user= (defn thread-add [x y]
   #_=   (thread
   #_= (try
   #_=   (if (zero? y)
   #_= x
   #_= (let [t (thread-add (inc x) (dec y))]
   #_=   (!! t)))
   #_=   (catch Throwable e (println e)
 #'user/thread-add
 user= (!! (thread-add 10 10))
 20
 user= (!! (thread-add 10 2000))
 Exception in thread async-thread-macro-1986 java.lang.OutOfMemoryError: 
 unable to create new native thread
 at java.lang.Thread.start0(Native Method)
 at java.lang.Thread.start(Thread.java:691)
 at 
 java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:943)
 at 
 java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.java:992)
 at 
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
 at 
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
 at java.lang.Thread.run(Thread.java:722)


 --
 paul.butcher-msgCount++

 Silverstone, Brands Hatch, Donington Park...
 Who says I have a one track mind?

 http://www.paulbutcher.com/
 LinkedIn: http://www.linkedin.com/in/paulbutcher
 Skype: paulrabutcher



  
 On 8 Dec 2013, at 14:21, Alex Miller al...@puredanger.com javascript: 
 wrote:

 If you're starting with lein repl then I would expect errors to be printed 
 at the console - that's the actual process running the code. It's also 
 possible that the thread's untaught exception handler doesn't print. I know 
 that the expectation for async go blocks is that you should catch and 
 handle any error. Have tried catching Throwable in your thread block and 
 printing?

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




-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


core.async/thread failing silently

2013-12-07 Thread Paul Butcher
Consider the following function that adds two numbers exceptionally 
inefficiently by creating lots of threads:

user= (require '[clojure.core.async :refer [thread !!]])
nil
user= (defn thread-add [x y]
  #_=   (thread
  #_= (if (zero? y)
  #_=   x
  #_=   (let [t (thread-add (inc x) (dec y))]
  #_= (!! t)
#'user/thread-add

This works for small numbers:

user= (!! (thread-add 10 10))
20
user= (!! (thread-add 10 1000))
1010

Unsurprisingly, it fails after a certain point, because the JVM simply can't 
create enough threads. But what I find surprising is that it fails completely 
silently - no error message, just a nil return:

user= (!! (thread-add 10 2000))
nil

Is this what I should expect? Is there any way to persuade the REPL to show me 
errors in this kind of situation?

--
paul.butcher-msgCount++

Silverstone, Brands Hatch, Donington Park...
Who says I have a one track mind?

http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
Skype: paulrabutcher




-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.