Why is main executable busy when calling external executable with Shelly.Background

130 Views Asked by At

I am trying to write a program with Shelly to compile Delphi projects in parallel. I thought the program would be blocked while waiting for the Delphi compilers to return. But my program starts to max out one CPU-core after compiled 2 projects. I couldn't work out what it's so busy doing. Please help? Thanks.

ps: I am quite new to Haskell, if I'm not implementing this the right way, pointers are appreciated.

{-# LANGUAGE OverloadedStrings, ExtendedDefaultRules #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
import Shelly 
import Shelly.Background

import Control.Monad
import Control.Arrow
import System.IO.Temp (withSystemTempDirectory)
import System.Directory (getCurrentDirectory)
import System.FilePath (splitFileName)
import Data.Text.Lazy (Text, pack)
default (Int, Text)

dcc32 = command "dcc32" ["-RC:\\Program Files\\Borland\\BDS\\4.0\\Lib", "-Q", "-H", "-W", "-B"]

compile project = liftIO $ withSystemTempDirectory "TempDCU_" compile'
  where
    compile' tmpDir = shellyNoDir $ silently $ 
      chdir dir (dcc32 [toTextIgnore file, pack $ "-N" ++ tmpDir])
    (dir, file) = mapTuple (fromText . pack) $ splitFileName project
    mapTuple = join (***)

compilePooled n projects = shellyNoDir $ jobs n (\job -> mapM (background job . compile) projects)

projectList = [
    "C:\\Path\\to\\project1.dpr",
    "C:\\Path\\to\\project2.dpr",
    "C:\\Path\\to\\project3.dpr",
    "C:\\Path\\to\\project4.dpr",
    ]

main = do
  output <- compilePooled 2 projectList
  shellyNoDir $ mapM getBgResult output >>= mapM_ inspect 
0

There are 0 best solutions below