[Haskell-cafe] memory usage in repeated reading of an external program's output

Dougal Stanton ithika at gmail.com
Thu Jun 21 06:55:10 EDT 2007


On 21/06/07, Andrea Rossato <mailing_list at istitutocolli.org> wrote:


> runComLoop :: String -> IO ()
> runComLoop command =
>     do (r,w) <- createPipe
>        wh <- fdToHandle w
>        hSetBuffering wh LineBuffering
>        p <- runProcess command [] Nothing Nothing Nothing (Just wh) (Just wh)
>        rh <- fdToHandle r
>        str <- hGetLine rh
>        rc <- handleToFd rh
>        hClose rh
>        closeFd rc
>        -- get and print the status of handles
>        swh <- hShow wh
>        srh <- hShow rh
>        putStrLn $ show swh
>        putStrLn $ show srh
>
>        putStrLn str
>        threadDelay $ 100000 * 1
>        runComLoop command
>
> main = runComLoop "date"

I honestly don't know the answer to this, and no doubt someone
intelligent will swoop in momentarily - but have you tried decomposing
runComLoop into smaller chunks to see which is using the most memory?
You could also try the 'bracket' function, which I find enormously
useful for showing which handles, etc are in scope.

Cheers,

D.


More information about the Haskell-Cafe mailing list