Last active
July 6, 2016 17:47
-
-
Save charles-cooper/95bdf602c410ec7ebb531b61c8b91be2 to your computer and use it in GitHub Desktop.
waitForProcess bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import System.Process | |
import Control.Concurrent | |
main :: IO () | |
main = do | |
(_, _, _, p) <- createProcess ((shell "sleep 1") { create_group = True }) | |
forkIO $ waitForProcess p >>= print | |
threadDelay 10 | |
-- interruptProcessGroupOf p | |
waitForProcess p >>= print | |
putStrLn "Success!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 'Safe' version | |
{-# LANGUAGE ScopedTypeVariables #-} | |
module Main where | |
import System.Process | |
import Control.Concurrent | |
import Control.Exception | |
import System.Exit | |
waitForProcessSafe :: ProcessHandle -> IO ExitCode | |
waitForProcessSafe p = waitForProcess p | |
`catch` (\(e :: IOError) -> do | |
threadDelay 1 -- give the other thread enough time to acquire the lock | |
waitForProcess p) | |
main :: IO () | |
main = do | |
(_, _, _, p) <- createProcess ((shell "sleep 1") { create_group = True }) | |
forkIO $ waitForProcessSafe p >>= print | |
threadDelay 10 | |
-- interruptProcessGroupOf p | |
waitForProcessSafe p >>= print | |
putStrLn "Success!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment