pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  1. <tfoot id='nU0Um'></tfoot>
      <bdo id='nU0Um'></bdo><ul id='nU0Um'></ul>

      <legend id='nU0Um'><style id='nU0Um'><dir id='nU0Um'><q id='nU0Um'></q></dir></style></legend>

      <small id='nU0Um'></small><noframes id='nU0Um'>

    1. <i id='nU0Um'><tr id='nU0Um'><dt id='nU0Um'><q id='nU0Um'><span id='nU0Um'><b id='nU0Um'><form id='nU0Um'><ins id='nU0Um'></ins><ul id='nU0Um'></ul><sub id='nU0Um'></sub></form><legend id='nU0Um'></legend><bdo id='nU0Um'><pre id='nU0Um'><center id='nU0Um'></center></pre></bdo></b><th id='nU0Um'></th></span></q></dt></tr></i><div class="xb7tphj" id='nU0Um'><tfoot id='nU0Um'></tfoot><dl id='nU0Um'><fieldset id='nU0Um'></fieldset></dl></div>

      Python 多處理只使用一個(gè)核心

      Python multiprocessing utilizes only one core(Python 多處理只使用一個(gè)核心)

      1. <legend id='du3WJ'><style id='du3WJ'><dir id='du3WJ'><q id='du3WJ'></q></dir></style></legend>
      2. <i id='du3WJ'><tr id='du3WJ'><dt id='du3WJ'><q id='du3WJ'><span id='du3WJ'><b id='du3WJ'><form id='du3WJ'><ins id='du3WJ'></ins><ul id='du3WJ'></ul><sub id='du3WJ'></sub></form><legend id='du3WJ'></legend><bdo id='du3WJ'><pre id='du3WJ'><center id='du3WJ'></center></pre></bdo></b><th id='du3WJ'></th></span></q></dt></tr></i><div class="lh5jnht" id='du3WJ'><tfoot id='du3WJ'></tfoot><dl id='du3WJ'><fieldset id='du3WJ'></fieldset></dl></div>

        <small id='du3WJ'></small><noframes id='du3WJ'>

          <bdo id='du3WJ'></bdo><ul id='du3WJ'></ul>
          <tfoot id='du3WJ'></tfoot>

            <tbody id='du3WJ'></tbody>

              • 本文介紹了Python 多處理只使用一個(gè)核心的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                限時(shí)送ChatGPT賬號(hào)..

                我正在嘗試使用 標(biāo)準(zhǔn) python 文檔中的代碼片段來學(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)

                問題:盡管啟動(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?

                最好的問候,

                保羅

                #
                # Simple example which uses a pool of workers to carry out some tasks.
                #
                # Notice that the results will probably not come out of the output
                # queue in the same in the same order as the corresponding tasks were
                # put on the input queue.  If it is important to get the results back
                # in the original order then consider using `Pool.map()` or
                # `Pool.imap()` (which will save on the amount of code needed anyway).
                #
                # Copyright (c) 2006-2008, R Oudkerk
                # All rights reserved.
                #
                
                import time
                import random
                
                from multiprocessing import Process, Queue, current_process, freeze_support
                
                #
                # Function run by worker processes
                #
                
                def worker(input, output):
                    for func, args in iter(input.get, 'STOP'):
                        result = calculate(func, args)
                        output.put(result)
                
                #
                # Function used to calculate result
                #
                
                def calculate(func, args):
                    result = func(*args)
                    return '%s says that %s%s = %s' % 
                        (current_process().name, func.__name__, args, result)
                
                #
                # Functions referenced by tasks
                #
                
                def mul(a, b):
                    time.sleep(0.5*random.random())
                    return a * b
                
                def plus(a, b):
                    time.sleep(0.5*random.random())
                    return a + b
                
                
                def test():
                    NUMBER_OF_PROCESSES = 4
                    TASKS1 = [(mul, (i, 7)) for i in range(500)]
                    TASKS2 = [(plus, (i, 8)) for i in range(250)]
                
                    # Create queues
                    task_queue = Queue()
                    done_queue = Queue()
                
                    # Submit tasks
                    for task in TASKS1:
                        task_queue.put(task)
                
                    # Start worker processes
                    for i in range(NUMBER_OF_PROCESSES):
                        Process(target=worker, args=(task_queue, done_queue)).start()
                
                    # Get and print results
                    print 'Unordered results:'
                    for i in range(len(TASKS1)):
                       print '	', done_queue.get()
                
                    # Add more tasks using `put()`
                    for task in TASKS2:
                        task_queue.put(task)
                
                    # Get and print some more results
                    for i in range(len(TASKS2)):
                        print '	', done_queue.get()
                
                    # Tell child processes to stop
                    for i in range(NUMBER_OF_PROCESSES):
                        task_queue.put('STOP')
                
                test()
                

                推薦答案

                嘗試將 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:

                def mul(a, b):
                    for i in xrange(100000):
                        j = i**2
                    return a * b
                
                def plus(a, b):
                    for i in xrange(100000):
                        j = i**2
                    return a + b
                

                這篇關(guān)于Python 多處理只使用一個(gè)核心的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                Passing multiple parameters to pool.map() function in Python(在 Python 中將多個(gè)參數(shù)傳遞給 pool.map() 函數(shù))
                multiprocessing.pool.MaybeEncodingError: #39;TypeError(quot;cannot serialize #39;_io.BufferedReader#39; objectquot;,)#39;(multiprocessing.pool.MaybeEncodingError: TypeError(cannot serialize _io.BufferedReader object,)) - IT屋-程序員軟件開
                Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?(Python 多進(jìn)程池.當(dāng)其中一個(gè)工作進(jìn)程確定不再需要完成工作時(shí),如何退出腳本?) - IT屋-程序員
                How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊(duì)列引用傳遞給 pool.map_async() 管理的函數(shù)?)
                yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯(cuò)誤的另一個(gè)混淆,“模塊對象沒有屬性“f)

                  <small id='UWWiq'></small><noframes id='UWWiq'>

                  <tfoot id='UWWiq'></tfoot>

                    • <bdo id='UWWiq'></bdo><ul id='UWWiq'></ul>
                      1. <i id='UWWiq'><tr id='UWWiq'><dt id='UWWiq'><q id='UWWiq'><span id='UWWiq'><b id='UWWiq'><form id='UWWiq'><ins id='UWWiq'></ins><ul id='UWWiq'></ul><sub id='UWWiq'></sub></form><legend id='UWWiq'></legend><bdo id='UWWiq'><pre id='UWWiq'><center id='UWWiq'></center></pre></bdo></b><th id='UWWiq'></th></span></q></dt></tr></i><div class="5z7jvpd" id='UWWiq'><tfoot id='UWWiq'></tfoot><dl id='UWWiq'><fieldset id='UWWiq'></fieldset></dl></div>
                        <legend id='UWWiq'><style id='UWWiq'><dir id='UWWiq'><q id='UWWiq'></q></dir></style></legend>

                            <tbody id='UWWiq'></tbody>
                        1. 主站蜘蛛池模板: 粒米特测控技术(上海)有限公司-测功机_减速机测试台_电机测试台 | 艺术涂料_进口艺术涂料_艺术涂料加盟_艺术涂料十大品牌 -英国蒙太奇艺术涂料 | 控显科技 - 工控一体机、工业显示器、工业平板电脑源头厂家 | 大型低温冷却液循环泵-低温水槽冷阱「厂家品牌」京华仪器_京华仪器 | NM-02立式吸污机_ZHCS-02软轴刷_二合一吸刷软轴刷-厦门地坤科技有限公司 | 小程序开发公司_APP开发多少钱_软件开发定制_微信小程序制作_客户销售管理软件-济南小溪畅流网络科技有限公司 | 盐城网络公司_盐城网站优化_盐城网站建设_盐城市启晨网络科技有限公司 | 短信通106短信接口验证码接口群发平台_国际短信接口验证码接口群发平台-速度网络有限公司 | AGV叉车|无人叉车|AGV智能叉车|AGV搬运车-江西丹巴赫机器人股份有限公司 | 小学教案模板_中学教师优秀教案_高中教学设计模板_教育巴巴 | 成都热收缩包装机_袖口式膜包机_高速塑封机价格_全自动封切机器_大型套膜机厂家 | 韦伯电梯有限公司| 济南拼接屏_山东液晶拼接屏_济南LED显示屏—维康国际官网 | 美名宝起名网-在线宝宝、公司、起名平台 | PVC快速门-硬质快速门-洁净室快速门品牌厂家-苏州西朗门业 | 接地电阻测试仪[厂家直销]_电缆故障测试仪[精准定位]_耐压测试仪-武汉南电至诚电力设备 | NM-02立式吸污机_ZHCS-02软轴刷_二合一吸刷软轴刷-厦门地坤科技有限公司 | 一体化隔油提升设备-餐饮油水分离器-餐厨垃圾处理设备-隔油池-盐城金球环保产业发展有限公司 | 登车桥动力单元-非标液压泵站-非标液压系统-深圳市三好科技有限公司 | 医养体检包_公卫随访箱_慢病随访包_家签随访包_随访一体机-济南易享医疗科技有限公司 | atcc网站,sigma试剂价格,肿瘤细胞现货,人结肠癌细胞株购买-南京科佰生物 | 塑胶地板-商用PVC地板-pvc地板革-安耐宝pvc塑胶地板厂家 | 低温柔性试验仪-土工布淤堵-沥青车辙试验仪-莱博特(天津)试验机有限公司 | 股指期货-期货开户-交易手续费佣金加1分-保证金低-期货公司排名靠前-万利信息开户 | 除湿机|工业除湿机|抽湿器|大型地下室车间仓库吊顶防爆除湿机|抽湿烘干房|新风除湿机|调温/降温除湿机|恒温恒湿机|加湿机-杭州川田电器有限公司 | 非甲烷总烃分析仪|环控百科| 组织研磨机-高通量组织研磨仪-实验室多样品组织研磨机-东方天净 传递窗_超净|洁净工作台_高效过滤器-传递窗厂家广州梓净公司 | 中高频感应加热设备|高频淬火设备|超音频感应加热电源|不锈钢管光亮退火机|真空管烤消设备 - 郑州蓝硕工业炉设备有限公司 | 实验室pH计|电导率仪|溶解氧测定仪|离子浓度计|多参数水质分析仪|pH电极-上海般特仪器有限公司 | TPU薄膜_TPU薄膜生产厂家_TPU热熔胶膜厂家定制_鑫亘环保科技(深圳)有限公司 | 加热制冷恒温循环器-加热制冷循环油浴-杭州庚雨仪器有限公司 | MTK核心板|MTK开发板|MTK模块|4G核心板|4G模块|5G核心板|5G模块|安卓核心板|安卓模块|高通核心板-深圳市新移科技有限公司 | 济南轻型钢结构/济南铁艺护栏/济南铁艺大门-济南燕翔铁艺制品有限公司 | 挤塑板-XPS挤塑板-挤塑板设备厂家[襄阳欧格] | 污水提升器,污水提升泵,地下室排水,增压泵,雨水泵,智能供排水控制器-上海智流泵业有限公司 | 换网器_自动换网器_液压换网器--郑州海科熔体泵有限公司 | 中空玻璃生产线,玻璃加工设备,全自动封胶线,铝条折弯机,双组份打胶机,丁基胶/卧式/立式全自动涂布机,玻璃设备-山东昌盛数控设备有限公司 | 扫地车厂家-山西洗地机-太原电动扫地车「大同朔州吕梁晋中忻州长治晋城洗地机」山西锦力环保科技有限公司 | 天一线缆邯郸有限公司_煤矿用电缆厂家_矿用光缆厂家_矿用控制电缆_矿用通信电缆-天一线缆邯郸有限公司 | 智能家居全屋智能系统多少钱一套-小米全套价格、装修方案 | 京港视通报道-质量走进大江南北-京港视通传媒[北京]有限公司 |