[Haskell-cafe] timeout and waitForProcess
bauertim at eecs.orst.edu
Tue Nov 20 19:24:32 EST 2007
Does anyone know if the new System.Timeout.timeout combinator can wakeup from
System.Process.waitForProcess? I have not been able to make this work, and
it appears as though the timeout exception is thrown only after
waitForProcess returns normally (if it ever does). I am using Windows and
halfSecond = 500000
example = timeout halfSecond sleepy
sleepy = do
(inp,out,err,pid) <- runInteractiveProcess "sleep.exe" ["10"] Nothing
forkOS (ioGobbler out)
forkOS (ioGobbler err)
waitForProcess pid -- CAN timeout INTERRUPT THIS?
return "PROCESS FINISHED"
ioGobbler :: Handle -> IO ()
ioGobbler h = catch (ioDiscarder h) eofHandler
ioDiscarder :: Handle -> IO ()
ioDiscarder h = do hGetChar h >> ioDiscarder h
eofHandler :: IOError -> IO ()
eofHandler e | isEOFError e = return ()
| otherwise = ioError e
Executing `example' from ghci will spawn (sleep.exe 10) which sleeps for 10
seconds. The timeout should happen in half a second (giving the thread time
to get blocked into waitForProcess). However, instead, things block for ten
seconds (until sleep.exe exits and waitForProcess returns normally).
While a workaround is to spin and sleep with the getProcessExitCode and
threadDelay, it seems like an inappropriate hack. The documentation for
timeout lists some functions that are interruptible, but is not mean to be a
View this message in context: http://www.nabble.com/timeout-and-waitForProcess-tf4847280.html#a13868823
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
More information about the Haskell-Cafe