I'm using the FSNotify package to watch my filesystem for changes to markdown files, so I can run them through Pandoc automatically. However, I'm having trouble getting the manager to exit nicely.
As it stands, my code is based on Yesod's use of the same package:
module Main where
import System.FSNotify
import Filesystem (getWorkingDirectory)
import System.Exit
import Control.Concurrent
main = do
cwd <- getWorkingDirectory
putStrLn "Watching current directory, press RETURN to exit."
withManager $ \man -> do
_ <- forkIO $ do
watchTree man cwd (const True) $ \fp -> print fp
_ <- getLine
exitSuccess
When I use runhaskell
, the program works perfectly, but if I compile it to an executable (using ghc --make
), when I press enter, my terminal becomes unresponsive. I'm compiling this on Windows 7 64-bit.
EDIT: Completed code. Well, not entirely completed - there's still more I want to do with this - but working.
Whenever I see a question of the form "works in GHCi, hangs when compiled", I think to myself "you need the threaded runtime".
Try recompiling with -threaded
and see if that helps.
(GHCi is compiled with this flag, which explains the difference. I do recall there's some difference in how external function calls work depending on whether you use the threaded runtime or not...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With