我正在关注本教程并查看源代码中的测试用例。我的代码SimplePool.hs
在源代码中使用并创建了以下文件:(片段)
sampleTask :: (TimeInterval, String) -> Process String
sampleTask (t, s) = sleep t >> return s
$(remotable ['sampleTask])
jobTest :: MVar (AsyncResult (Either String String)) -> Process ()
jobTest result = do
pid <- startTestPool 1 -- start the pool of workers here only one worker
job <- return $ ($(mkClosure 'sampleTask) (seconds 2, "foobar"))
-- callAsync put job into pool
p <- callAsync pid job
a <- wait p
setResult result a
where
setResult :: MVar a -> a -> Process ()
setResult mvar x = liftIO $ putMVar mvar x
startTestPool :: Int -> Process ProcessId
startTestPool s = spawnLocal $ do
_ <- runPool s
return ()
runPool :: Int -> Process (Either (InitResult (Pool String)) TerminateReason)
runPool s =
-- setting a to String
let s' = poolServer :: ProcessDefinition (Pool String)
in simplePool s s'
myRemoteTable :: RemoteTable
myRemoteTable = Control.Distributed.Process.Platform.__remoteTable initRemoteTable
main :: IO ()
main = do
Right (transport, _) <- createTransportExposeInternals
"127.0.0.1" "9901" defaultTCPParameters
localNode <- newLocalNode transport myRemoteTable
result <- newEmptyMVar
pid <- forkProcess localNode $ jobTest result
ans <- takeMVar result
putStrLn $ show pid
putStrLn $ show ans
运行后出现此错误:
AsyncFailed (DiedException "exit-from=pid://127.0.0.1:9901:0:6")
如果我错了,请纠正我,我认为作业没有正确运行,一定是从属进程有问题。p <- callAsync pid job
我认为这行代码是将任务传递给从属进程执行的地方。我查看了库以找到callAsync
. 关键行callAsyncUsing
是sendTo sid (CallMessage msg (Pid wpid))
函数将任务传递给 poolServer 的位置。
acceptTask
行中的 SimplePool.hsasyncHandle <- async proc
是我认为他们生成一个新进程来执行任务的地方。所以我认为也许异步进程没有完成运行导致调用者过早终止?或者可能是该过程没有正确产生?关于调试这个的最佳方法的任何想法?另外,有人可以指出我正确的方向,以找出如何使 poolSever 跨越不同的节点/不同的计算机(使用 Control.Distributed.Process.Platform.Async.AsyncChan?)?