[Hugs-bugs] File remains locked after crash

Neil Mitchell ndmitchell at gmail.com
Mon May 1 12:18:46 EDT 2006


Hi,

> This should be a better implementation of writeFile:
>
>         import Control.Exception
>         import System.IO
>
>         writeFile' :: FilePath -> String -> IO ()
>         writeFile' f txt = bracket (openFile f WriteMode) hClose
>                                 (flip hPutStr txt)

Yes, it works better in the error case, so is definately preferable.
Is there any reason why this isn't the standard definition of
writeFile? Especially in an interactive environment likes Hugs/GHCi.

The problem still remains however with the following command:

writeFile' "test4.txt" (show $ last [1..])

Which is non-terminating therefore requires the user to break the
program with Ctrl-C.  When the user presses Ctrl-C the bracket is not
run, so the file remains locked afterwards.

Thanks

Neil


More information about the Hugs-Bugs mailing list