multithreading - F# MailboxProcessor questions -
i've created console program using code http://fssnip.net/3k. , found that
i'd add "system.console.readline() |> ignore" @ end wait finish of threads. possible tell mailboxprocessors done , program can exit itself?
i tried change test url "www.google.com" invalid url , got following output. possible avoid "outputting race"?
http://www.google.co1m crawled agent 1. agaaaent gent 3 done. gent 2 done. 5 done. gent 4 done. agent usupervisor rl collector done. done. 1 done.
[edit]
the last output/crawling still terminated after using tomas's update http://fssnip.net/65. following output of program after changed "limit" 5 , added debugging messages. last line shows truncated url. way detect if crawlers finish execution?
[main] before crawl [crawl] before return result http://news.google.com crawled agent 1. [supervisor] reached limit http://www.gstatic.com/news/img/favicon.ico crawled agent 5. agent 2 done. [supervisor] reached limit agent 5 done. http://www.google.com/imghp?hl=en&tab=ni crawled agent 3. [supervisor] reached limit agent 3 done. http://www.google.com/webhp?hl=en&tab=nw crawled agent 4. [supervisor] reached limit agent 4 done. http://news.google.com/n
i changed main code
printfn "[main] before crawl" crawl "http://news.google.com" 5 |> async.runsynchronously printfn "[main] after crawl"
however, last printfn "[main] after crawl" never executed, unless add console.readline() @ end.
[edit 2]
the code runs fine under fsi. have same problem if run using fsi --use:program.fs --exec --quiet
i created snippet extends previous 1 2 features asked about: http://fssnip.net/65.
to solve this, added
start
message carriesasyncreplychannel<unit>
. when supervisor agent starts, waits message , saves reply channel later use. when completes, sends reply using channel.the function starts agent returns asynchronous workflow waits reply. can call
crawl
usingasync.runsynchronously
, complete when supervisor agent completes.to avoid race when printing, need synchronize prints. easiest way write new agent :-). agent receives strings , prints them output 1 one (so cannot interleaved). snippet hides standard
printfn
function new implementation sends strings agent.
Comments
Post a Comment