process
process copied to clipboard
Does not work with async exceptions
Given the code Proc.hs:
import System.Process
import System.Time.Extra
main = do
(t, e) <- duration $ timeout 2 $ system "sleep 5s"
print (showDuration t, e)
(t, e) <- duration $ timeout 2 $ do
(_, _, _, pid) <- createProcess (proc "sleep" ["5s"])
waitForProcess pid
print (showDuration t, e)
(t, e) <- duration $ timeout 2 $ do
withCreateProcess (proc "sleep" ["5s"]) $ \_ _ _ pid -> waitForProcess pid
print (showDuration t, e)
I observe:
C:\Neil\temp>ghc Proc.hs -package=process-1.6.2.0 && proc
[1 of 1] Compiling Main ( Proc.hs, Proc.o )
Linking Proc.exe ...
("5.06s",Just ExitSuccess)
("5.05s",Just ExitSuccess)
("5.04s",Just ExitSuccess)
C:\Neil\temp>ghc Proc.hs -package=process-1.6.2.0 -threaded && proc
[1 of 1] Compiling Main ( Proc.hs, Proc.o )
Linking Proc.exe ...
("5.48s",Nothing)
("5.49s",Nothing)
proc: terminateProcess: permission denied (Permission denied)
Running Windows 10, 64bit GHC 8.2.1, process 1.6.2.0. Requires the extra library to be installed and the sleep binary to be on %PATH%. I would expect all these functions to die around 2s, but none of the timeouts are effective.
Originally found when debugging an upstream bug in Shake: https://github.com/ndmitchell/shake/issues/538
Possibly related to https://ghc.haskell.org/trac/ghc/ticket/8684?
That one is about not being able to timeout hWaitForInput, but it's possible that waitpid() also should be interruptible.
This relies on the interruptible extension to the FFI to allow the wait to be interrupted by the async exception. See https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ffi-chap.html#interruptible-foreign-calls
It works on Linux (I just checked), but perhaps not Windows. I don't remember off hand whether it is supposed to work or not.