GTK and INotify don't work together

haskell

Solution

Compile (actually, technically, link) with `-threaded`. This way the inotify thread will be evacuated from the `main` execution context before the `mainGUI` loop goes into C-land and stops cooperatively switching to the GHC runtime. More details on multi-threading and gtk are available at this post I wrote a while ago.

Problem

Using GHC, on Ubuntu 13.10, iNotify works- ``` import Control.Concurrent import System.INotify main = do n <- initINotify addWatch n [Modify] "/home/fred/" $ \event -> do putStrLn $ "file changed: " ++ show event threadDelay 10000000 ``` and GTK2HS works- ``` import Graphics.UI.Gtk main = do initGUI {-Add your widgets here.... or don't, the bug appears either way.-} mainGUI ``` But if I put the two together, inotify never triggers. (it compiles and runs though....) ``` main = do n <- initINotify addWatch n [Modify] "/home/fred/" $ \event -> do putStrLn $ "file changed: " ++ show event initGUI mainGUI ``` I've tried putting the inotify and GTK stuff in separate threads, it made no difference. I suspect something like a signal collision between the libs.... Oh, and in case it matters, I am trying to build a small tool that runs in the background, watches for file changes, and displays some info in the application indicator when this happens. Note- To trigger iNotify, just create or modify a file in the directory given in addWatch.... ``` echo "abcd" > /home/fred/aFile ``` `touch` doesn't seem to work.

Original source