使用Shelly.Background调用外部可执行文件时,为什么主可执行文件繁忙

时间:2012-10-02 04:56:57

标签: multithreading haskell concurrency shelly

我正在尝试用Shelly编写一个程序来并行编译Delphi项目。我认为程序会在等待Delphi编译器返回时被阻止。但是我的程序在编译了2个项目后开始最大化一个CPU核心。我无法解决它忙碌的事情。请帮忙?感谢。

ps:我对Haskell很陌生,如果我没有以正确的方式实现这一点,那么指针就会受到赞赏。

{-# 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 个答案:

没有答案