使用 GHC,在 Ubuntu 13.10 上,iNotify 工作-

import Control.Concurrent
import System.INotify

main = do
    n <- initINotify
    addWatch n [Modify] "/home/fred/" $ \event -> do
        putStrLn $ "file changed: " ++ show event
    threadDelay 10000000

和 GTK2HS 作品-
import Graphics.UI.Gtk

main = do
    initGUI
    {-Add your widgets here....  or don't, the bug appears either way.-}
    mainGUI

但是如果我把两者放在一起,inotify 永远不会触发。 (虽然它编译并运行....)
main = do
    n <- initINotify
    addWatch n [Modify] "/home/fred/" $ \event -> do
        putStrLn $ "file changed: " ++ show event
    initGUI
    mainGUI

我试过将 inotify 和 GTK 的东西放在单独的线程中,没有区别。我怀疑像库之间的信号冲突之类的东西....

哦,以防万一,我正在尝试构建一个在后台运行的小工具,监视文件更改,并在发生这种情况时在应用程序指示器中显示一些信息。

笔记-

要触发 iNotify,只需在 addWatch... 中给定的目录中创建或修改一个文件。
echo "abcd" > /home/fred/aFile
touch 似乎不起作用。

最佳答案

使用 -threaded 编译(实际上,技术上,链接)。这样,在 main 循环进入 C-land 并停止协作切换到 GHC 运行时之前,inotify 线程将从 mainGUI 执行上下文中撤离。关于多线程和 gtk 的更多详细信息可以在我不久前写的 this post 中找到。

关于haskell - GTK 和 INotify 不能一起工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21864134/

10-12 12:35