Did you mean to create a bigger computation than `(factorial 20000)`?
It takes only about 5 msec on my machine, but adding a couple of extra
zeros makes it time out.

Converting the result of `(factorial 20000)` to a string takes a bit
longer than the arithmetic, and printing out the result in DrRacket
takes much longer than 2 seconds --- due to scrolling while parts of
the number print out --- but all of that happens outside the sandbox.

At Sun, 08 Nov 2015 00:35:09 +0200, jukka.tuomi...@finndesign.fi wrote:
> 
> Hi all,
> 
> I'm probably doing something wrong here, but for some reason 
> "custodian-shutdown-all" doesn't always interrupt the execution as the 
> last test case below shows. It continues execution until finished.
> 
> Any ideas how to get this working?
> 
> br, jukka
> 
> 
> ---
> 
> #lang racket/load
> 
> (require math/number-theory)
> 
> 
> (define (when-works-in-given-seconds time-limit thunk)
>    (define start-time 0)
>    (define output "initial-state")
>    (define main-cust (make-custodian))
>    (define thread:thunk "")
>    (define (loop delay)
>      (cond ((not (equal? "initial-state" output))
>             (begin (custodian-shutdown-all main-cust)
>                    output))
>            ((> (- (current-seconds) start-time) time-limit)
>             (begin (custodian-shutdown-all main-cust)
>                    "Time-limit exceeded!"))
>            (else (begin (- (current-seconds) start-time)
>                         (sleep delay)
>                         (loop delay) ))))
>    (set! start-time (current-seconds))
>    (thread (lambda ()  (parameterize ((current-custodian main-cust))
>                          (thread (lambda () (with-handlers ((exn:fail? 
> (lambda (exn) (set! output "Execution failed!"))))  (set! output (eval 
> thunk))))))))
>    (loop 0.1))
> 
> 
> ;test cases
> 
> (print (when-works-in-given-seconds 2 '(/ 5 5)))
> (newline)(sleep 2)
> 
> (print (when-works-in-given-seconds 2 '(/ 5 0)))
> (newline)(sleep 2)
> 
> (print (when-works-in-given-seconds 2 '(sleep 10)))
> (newline)(sleep 2)
> 
> (print (when-works-in-given-seconds 2 '(factorial 20000)))
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to