問(wèn)題描述
我正在嘗試使用 標(biāo)準(zhǔn) python 文檔中的代碼片段來(lái)學(xué)習(xí)如何使用多處理模塊.代碼粘貼在此消息的末尾.我在四核機(jī)器上的 Ubuntu 11.04 上使用 Python 2.7.1(根據(jù)系統(tǒng)監(jiān)視器,由于超線程,它給了我八個(gè)內(nèi)核)
I'm trying out a code snippet from the standard python documentation to learn how to use the multiprocessing module. The code is pasted at the end of this message. I'm using Python 2.7.1 on Ubuntu 11.04 on a quad core machine (which according to the system monitor gives me eight cores due to hyper threading)
問(wèn)題:盡管啟動(dòng)了多個(gè)進(jìn)程,但所有工作負(fù)載似乎都安排在一個(gè)內(nèi)核上,利用率接近 100%.有時(shí),所有工作負(fù)載都會(huì)遷移到另一個(gè)核心,但工作負(fù)載從未在它們之間分配.
Problem: All workload seems to be scheduled to just one core, which gets close to 100% utilization, despite the fact that several processes are started. Occasionally all workload migrates to another core but the workload is never distributed among them.
任何想法為什么會(huì)這樣?
Any ideas why this is so?
最好的問(wèn)候,
保羅
推薦答案
嘗試將 time.sleep
替換為實(shí)際需要 CPU 的東西,您將看到 multiprocess
有效正好!例如:
Try replacing the time.sleep
with something that actually requires CPUs and you will see the multiprocess
works just fine! For example:
這篇關(guān)于Python 多處理只使用一個(gè)核心的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!