diff options
| author | bringert <unknown> | 2005-11-07 21:27:13 +0000 |
|---|---|---|
| committer | bringert <unknown> | 2005-11-07 21:27:13 +0000 |
| commit | 71cd8efe2740f71c93f96c296b55164c3096e79b (patch) | |
| tree | abddfbbb6249764877a0854fa253710744d1a98e /src/GF | |
| parent | abf9823601eac8beb9281ef5cd48e088793442b2 (diff) | |
Restore old signal handler after each computation.
Diffstat (limited to 'src/GF')
| -rw-r--r-- | src/GF/System/Signal.hs | 19 |
1 files 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 |
