Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Condoluci committed Apr 1, 2022
1 parent 5957897 commit d299f9a
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Data.List.Extra
import Control.Applicative
import Prelude
import System.IO.Extra
import System.Posix.Signals


data Session = Session
Expand Down Expand Up @@ -66,16 +67,29 @@ withSession f = do
debugShutdown "Finish finally"


-- | Kill. Wait just long enough to ensure you've done the job, but not to see the results.
-- | Kill a Ghci session.
-- Wait until the child Ghci process has exited.
kill :: Ghci -> IO ()
kill ghci = ignored $ do
timeout 5 $ do
debugShutdown "Before quit"
ignored $ quit ghci
debugShutdown "After quit"
debugShutdown "Before terminateProcess"
ignored $ terminateProcess $ process ghci
debugShutdown "After terminateProcess"
-- When a user presses Ctrl-C twice, the Haskell RTS will
-- terminate ghcid, leaving the child ghci process running
-- silently in the background.
-- To avoid leaking ghci children, we temporarily disable
-- the default signal handler for SIGINT. It's going to
-- be restored when ghci exits.
-- See: https://github.com/ndmitchell/ghcid/issues/286
bracket
(installHandler sigINT Ignore Nothing)
(\h -> installHandler sigINT h Nothing) $ \_ -> do
timeout 5 $ do
debugShutdown "Before quit"
ignored $ quit ghci
debugShutdown "After quit"
debugShutdown "Before terminateProcess"
ignored $ terminateProcess $ process ghci
debugShutdown "After terminateProcess"
waitForProcess $ process ghci
debugShutdown "After withForProcess"
-- Ctrl-C after a tests keeps the cursor hidden,
-- `setSGR []`didn't seem to be enough
-- See: https://github.com/ndmitchell/ghcid/issues/254
Expand Down

0 comments on commit d299f9a

Please sign in to comment.