I am trying to write a scsh program that executes a process in such a
way that if it doesn't complete in a certain time period the program
gives up on it. I've never been entirely successful in getting this
to work and things seem to have gotten worse in scsh-0.6.0.
I have a procedure called `execute/timeout' that takes two
arguments---a subprocedure and a number of seconds---and attempts to
execute the subprocedure. The intended behavior is that if the
subprocedure finishes in the alloted number of seconds then
execute/timeout returns its value. If it doesn't finish the return
value is 'timeout. The actual behavior is something else. (I have
appended the definition of execute/timeout and a transcript of a
sample run below.)
I would not be happy with the function even if it somehow worked. It
seems to me that the alarm interrupt handler should clean up after the
incomplete subprocedure, but I don't see how to do that. I am
prepared to believe that there is an entirely better way of writing
the function using threads but I don't see how to do that either.
My purpose in sending this message is to ask if anyone has already
written a procedure that does what I am describing, or to ask if they
have pointers on how to do so. Also, I want to describe how my
procedure behaves in case it demonstrates a bug in scsh---but the more
I think about it the more I believe this is my fault.
Thanks for reading this.
-----------------------------------------------------------------
;;; This is scsh-0.6.0 on Solaris2.6.
(define (execute/timeout proc sec)
(let ((alrm-handler (interrupt-handler interrupt/alrm))
(result
(call-with-current-continuation
(lambda (break)
(set-interrupt-handler interrupt/alrm
(lambda (i) (break 'timeout)))
(itimer sec)
(with-enabled-interrupts (interrupt-set interrupt/alrm)
(proc))))))
(set-interrupt-handler interrupt/alrm alrm-handler)
(itimer 0)
result))
> (execute/timeout
(lambda () (run (sleep 10)) 'done)
5)
'timeout
'done
>
Interrupt: post-gc
4>
Interrupt: post-gc
8>
Interrupt: post-gc
15>
Interrupt: post-gc
20>
Interrupt: post-gc
28> Scheme48 heap overflow
-----------------------------------------------------------------
--
Ed Kademan 508.651.3700
PHZ Capital Partners 508.653.1745 (fax)
321 Commonwealth Road <kademan@phz.com>
Wayland, MA 01778
|