[問題]multiprocessing ( Done

看板Python作者 (林佳)時間11年前 (2014/04/04 00:18), 編輯推噓2(207)
留言9則, 4人參與, 最新討論串1/1
目前需要使用到 multiprocessing 我要做到的是 開啟多個process 分別將資料進行 排序 排序法 def xxxxxSort( data_list ): #略 return sorted 目前找到的資料是用 multiprocessing.Pool 我可以用 multiprocessing.Pool 來達到 多process 執行 function ( print something) 但是我一直無法取到我 執行完 xxxxxSort 之後回傳的list 不過我有得到一些東西 像是 <multiprocessing.pool.ApplyResult object at 0x02716310> 請問有辦法使用 multiprocessing 來達到 多process 排序&回傳嗎 還是要透過 object at 0x02716310 來取得 list? 請求各路高手解答 -- ◢◤ ███◣ /// /// ███ ███ ███ ███ █▆▆ █▆▆ ██████◤ ψjimbox -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.166.145.1 ※ 文章網址: http://www.ptt.cc/bbs/Python/M.1396541882.A.49E.html

04/04 00:49, , 1F
p=multiprocessing.Pool(100)
04/04 00:49, 1F

04/04 00:50, , 2F
output_list = p.map(XXXXsort, input_list)
04/04 00:50, 2F

04/04 00:51, , 3F
print output_list
04/04 00:51, 3F

04/04 00:51, , 4F
[[1,4,5],[2,3],[7,9]]
04/04 00:51, 4F

04/04 00:51, , 5F
有錯請指定
04/04 00:51, 5F

04/04 01:02, , 6F
call .get()才會是函式的回傳值 話說樓上你有一百核嗎?
04/04 01:02, 6F

04/04 01:18, , 7F
1f 那樣寫是一百核還是允許最大100個process同時?
04/04 01:18, 7F

04/04 03:18, , 8F
感謝1F 方法可行 3Q
04/04 03:18, 8F

04/25 22:55, , 9F
100個process
04/25 22:55, 9F
文章代碼(AID): #1JFOcwIU (Python)
文章代碼(AID): #1JFOcwIU (Python)