I took a stab at it in pure core.async, unfortunately, it does not work; I
would be curious if anyone could explain why.
(use '[clojure.core.async :only [timeout http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure"
For processes, there is a https://github.com/Raynes/conch but I haven't
used it yet so I don't know how mature it is.
On Wed, Jan 22, 2014 at 10:45 PM, Cedric Greevey wrote:
> It's not safe if the thread is holding any locks. It *may* also leak
> native resources if the thread is holding those,
It's not safe if the thread is holding any locks. It *may* also leak native
resources if the thread is holding those, but native resources held by a
heap-allocated Java object are supposed to be cleaned up by the finalizer
if the object is GC'd, and I think Thread.stop properly removes that
thread'
So I guess this gets back to my earlier question: when is it safe to
terminate a thread?
I know that I often hit Ctrl-C in the REPL to terminate a long running
function, and I've never really worried about it screwing things up.
On Wed, Jan 22, 2014 at 1:29 PM, Shantanu Kumar wrote:
>
>
> On Th
On Thursday, 23 January 2014 02:37:43 UTC+5:30, puzzler wrote:
>
> Is there a convenient way within Clojure to launch a Clojure function or
> Java call in a separate process as opposed to a separate thread? Only way
> I know of is to literally shell out to the command prompt and launch a new
Is there a convenient way within Clojure to launch a Clojure function or
Java call in a separate process as opposed to a separate thread? Only way
I know of is to literally shell out to the command prompt and launch a new
executable.
On Wed, Jan 22, 2014 at 12:19 PM, Jozef Wagner wrote:
> If yo
If you want to be able to control an arbitrary long-running function, a
safe way is to run it in a separate process. That way you can safely
terminate it anytime you want. Of course this opens up a lot of other
issues :)
On Wed, Jan 22, 2014 at 9:15 PM, Mark Engelberg wrote:
> I think the f
I think the fib example is a good one in the sense that you are dealing
with an already function that takes a long time, and isn't written as a
loop.
But in general, I want to solve the problem for an arbitrary long-running
computation, for example, a call into a library that you don't control.
O
What is the task doing? If it is in a tight loop, it must check explicitly
whether the interrupt flag is set and abort. If it is waiting on some
resource, it will receive InterruptedException.
Regards,
Praki Prakash
On Wed, Jan 22, 2014 at 11:20 AM, Mark Engelberg
wrote:
> On Wed, Jan 22, 2014
On Wed, Jan 22, 2014 at 2:51 AM, Jozef Wagner wrote:
> You can put the computation into a future, and cancel the future after the
> timeout.
>
I experimented with that, but it didn't seem to work. I suspect that
"canceling a future" doesn't really do what I think it should do. I would
appreciat
You can put the computation into a future, and cancel the future after the
timeout.
BTW is it idiomatic to write to the timeout channel? I thought one should
use something like (alts!! [c (timeout 1000)]).
JW
On Wednesday, January 22, 2014 11:30:23 AM UTC+1, puzzler wrote:
>
> So far, this is
So far, this is the only way I've figured out that works:
(defn try-fib [n]
(let [ch (timeout 1000)
th (Thread. #(>!! ch (fib n)))
_ (.start th)
answer (http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Gr
Consider the really slow fib function:
(defn fib [n]
(if (< n 2) n (+ (fib (dec n)) (fib (- n 2)
Now, let's say I want to compute the fib of some number n and timeout and
return nil if it takes longer than a second.
(defn try-fib [n]
(let [ch (timeout 1000)]
(go (>! ch (fib n)))
(
13 matches
Mail list logo