I thought `current-subprocess-custodian-mode` would be the solution, but when I just tried your code (with Racket 6.12 on Mac OS), it first printed "Timed out", then printed “Finished” after a brief delay.
I get the same result if I put the `parameterize` directly around the call to `system`, and this happens with both DrRacket and the command-line racket repl. -Philip On Fri, Jul 20, 2018 at 3:36 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote: > At Fri, 20 Jul 2018 16:28:22 -0400, "'Leandro Facchinetti' via Racket > Users" wrote: > > Hi, > > > > I want to run a subprocess with a timeout. Here’s what I tried: > > > > #lang racket > > (require racket/sandbox) > > > > (with-handlers ([exn:fail:resource? (λ (e) (displayln "Timed out"))]) > > (with-limits 5 #f (system "sleep 10 && echo Finished"))) > > > > This doesn’t work, it prints both “Timed out” after 5 seconds and > “Finished” > > after 10 seconds. I wish ‘with-limits’ would stop the underlying > process, so > > I’d never see “Finished”. How should I do that? > > You can use `current-subprocess-custodian-mode`: > > #lang racket > (require racket/sandbox) > > (parameterize ([current-subprocess-custodian-mode 'kill]) > (with-handlers ([exn:fail:resource? (λ (e) (displayln "Timed out"))]) > (with-limits 5 #f (system "sleep 10 && echo Finished")))) > > -- > 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.