From 71cd8efe2740f71c93f96c296b55164c3096e79b Mon Sep 17 00:00:00 2001 From: bringert Date: Mon, 7 Nov 2005 21:27:13 +0000 Subject: [PATCH] Restore old signal handler after each computation. --- src/GF/System/Signal.hs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/GF/System/Signal.hs b/src/GF/System/Signal.hs index 7c39a53ca..cd5032100 100644 --- a/src/GF/System/Signal.hs +++ b/src/GF/System/Signal.hs @@ -5,9 +5,9 @@ -- Stability : (stability) -- Portability : (portability) -- --- > CVS $Date: 2005/11/07 20:15:05 $ +-- > CVS $Date: 2005/11/07 22:27:13 $ -- > CVS $Author: bringert $ --- > CVS $Revision: 1.1 $ +-- > CVS $Revision: 1.2 $ -- -- Allows SIGINT (Ctrl-C) to interrupt computations. ----------------------------------------------------------------------------- @@ -26,18 +26,19 @@ import System.Posix.Signals -- normally. -- NOTES: -- * This will replace any existing SIGINT --- handlers, and after the computation has completed --- the default handler will be installed for SIGINT. +-- handler during the action. After the computation +-- has completed the existing handler will be restored. -- * If the IO action is lazy (e.g. using readFile, -- unsafeInterleaveIO etc.) the lazy computation will -- not be interruptible, as it will be performed -- after the signal handler has been removed. runInterruptibly :: IO a -> IO (Either Exception a) -runInterruptibly a = do t <- myThreadId - installHandler sigINT (Catch (killThread t)) Nothing - x <- p `catch` h - installHandler sigINT Default Nothing - return x +runInterruptibly a = + do t <- myThreadId + oldH <- installHandler sigINT (Catch (killThread t)) Nothing + x <- p `catch` h + installHandler sigINT oldH Nothing + return x where p = a >>= \x -> return $! Right $! x h e = return $ Left e