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

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

        • <bdo id='uefoj'></bdo><ul id='uefoj'></ul>

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

      1. 使用具有最大同時進程數的 multiprocessing.Process

        Using multiprocessing.Process with a maximum number of simultaneous processes(使用具有最大同時進程數的 multiprocessing.Process)
        <i id='JeUZY'><tr id='JeUZY'><dt id='JeUZY'><q id='JeUZY'><span id='JeUZY'><b id='JeUZY'><form id='JeUZY'><ins id='JeUZY'></ins><ul id='JeUZY'></ul><sub id='JeUZY'></sub></form><legend id='JeUZY'></legend><bdo id='JeUZY'><pre id='JeUZY'><center id='JeUZY'></center></pre></bdo></b><th id='JeUZY'></th></span></q></dt></tr></i><div class="c0ok2g6" id='JeUZY'><tfoot id='JeUZY'></tfoot><dl id='JeUZY'><fieldset id='JeUZY'></fieldset></dl></div>

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

          • <tfoot id='JeUZY'></tfoot>
              <bdo id='JeUZY'></bdo><ul id='JeUZY'></ul>

                  <tbody id='JeUZY'></tbody>

                <legend id='JeUZY'><style id='JeUZY'><dir id='JeUZY'><q id='JeUZY'></q></dir></style></legend>
                  本文介紹了使用具有最大同時進程數的 multiprocessing.Process的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我有 Python 代碼:

                  from multiprocessing import Process
                  
                  def f(name):
                      print 'hello', name
                  
                  if __name__ == '__main__':
                      for i in range(0, MAX_PROCESSES):
                          p = Process(target=f, args=(i,))
                          p.start()
                  

                  運行良好.但是,MAX_PROCESSES 是可變的,可以是 1512 之間的任何值.由于我只在具有 8 內核的機器上運行此代碼,因此我需要確定是否可以限制允許同時運行的進程數.我查看了 multiprocessing.Queue,但它看起來不像我需要的 - 或者我可能錯誤地解釋了文檔.

                  which runs well. However, MAX_PROCESSES is variable and can be any value between 1 and 512. Since I'm only running this code on a machine with 8 cores, I need to find out if it is possible to limit the number of processes allowed to run at the same time. I've looked into multiprocessing.Queue, but it doesn't look like what I need - or perhaps I'm interpreting the docs incorrectly.

                  有沒有辦法限制同時運行的 multiprocessing.Process 的數量?

                  Is there a way to limit the number of simultaneous multiprocessing.Processs running?

                  推薦答案

                  使用 multiprocessing.Pool 可能是最明智的,它根據可用的最大內核數生成工作進程池您的系統,然后基本上在內核可用時提供任務.

                  It might be most sensible to use multiprocessing.Pool which produces a pool of worker processes based on the max number of cores available on your system, and then basically feeds tasks in as the cores become available.

                  標準文檔中的示例 (http://docs.python.org/2/library/multiprocessing.html#using-a-pool-of-workers)顯示也可以手動設置核心數:

                  The example from the standard docs (http://docs.python.org/2/library/multiprocessing.html#using-a-pool-of-workers) shows that you can also manually set the number of cores:

                  from multiprocessing import Pool
                  
                  def f(x):
                      return x*x
                  
                  if __name__ == '__main__':
                      pool = Pool(processes=4)              # start 4 worker processes
                      result = pool.apply_async(f, [10])    # evaluate "f(10)" asynchronously
                      print result.get(timeout=1)           # prints "100" unless your computer is *very* slow
                      print pool.map(f, range(10))          # prints "[0, 1, 4,..., 81]"
                  

                  如果您的代碼中需要,知道有 multiprocessing.cpu_count() 方法來計算給定系統上的內核數量也很方便.

                  And it's also handy to know that there is the multiprocessing.cpu_count() method to count the number of cores on a given system, if needed in your code.

                  這是一些似乎適用于您的特定情況的代碼草案:

                  Here's some draft code that seems to work for your specific case:

                  import multiprocessing
                  
                  def f(name):
                      print 'hello', name
                  
                  if __name__ == '__main__':
                      pool = multiprocessing.Pool() #use all available cores, otherwise specify the number you want as an argument
                      for i in xrange(0, 512):
                          pool.apply_async(f, args=(i,))
                      pool.close()
                      pool.join()
                  

                  這篇關于使用具有最大同時進程數的 multiprocessing.Process的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                  Passing multiple parameters to pool.map() function in Python(在 Python 中將多個參數傳遞給 pool.map() 函數)
                  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 多進程池.當其中一個工作進程確定不再需要完成工作時,如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊列引用傳遞給 pool.map_async() 管理的函數?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯誤的另一個混淆,“模塊對象沒有屬性“f)

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

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

                    • <bdo id='NZdlA'></bdo><ul id='NZdlA'></ul>

                        <tbody id='NZdlA'></tbody>
                      • <legend id='NZdlA'><style id='NZdlA'><dir id='NZdlA'><q id='NZdlA'></q></dir></style></legend>

                          • 主站蜘蛛池模板: 沈飞防静电地板__机房地板-深圳市沈飞防静电设备有限公司 | 恒温振荡混匀器-微孔板振荡器厂家-多管涡旋混匀器厂家-合肥艾本森(www.17world.net) | 污水处理设备维修_污水处理工程改造_机械格栅_过滤设备_气浮设备_刮吸泥机_污泥浓缩罐_污水处理设备_污水处理工程-北京龙泉新禹科技有限公司 | 佛山市德信昌电子有限公司| 东莞注册公司-代办营业执照-东莞公司注册代理记账-极刻财税 | 智能风向风速仪,风速告警仪,数字温湿仪,综合气象仪(气象五要素)-上海风云气象仪器有限公司 | 口信网(kousing.com) - 行业资讯_行业展会_行业培训_行业资料 | ★济南领跃标识制作公司★济南标识制作,标牌制作,山东标识制作,济南标牌厂 | 分光色差仪,测色仪,反透射灯箱,爱色丽分光光度仪,美能达色差仪维修_苏州欣美和仪器有限公司 | 编织人生 - 权威手工编织网站,编织爱好者学习毛衣编织的门户网站,织毛衣就上编织人生网-编织人生 | 钢骨架轻型板_膨石轻型板_钢骨架轻型板价格_恒道新材料 | 耐酸碱胶管_耐腐蚀软管总成_化学品输送软管_漯河利通液压科技耐油耐磨喷砂软管|耐腐蚀化学软管 | 铝合金电阻-无源谐波滤波器-上海稳达电讯设备厂 | 亮化工程,亮化设计,城市亮化工程,亮化资质合作,长沙亮化照明,杰奥思【官网】 | 代理记账_免费注册公司_营业执照代办_资质代办-【乐财汇】 | 石油/泥浆/不锈钢防腐/砂泵/抽砂泵/砂砾泵/吸砂泵/压滤机泵 - 专业石油环保专用泵厂家 | 半自动预灌装机,卡式瓶灌装机,注射器灌装机,给药器灌装机,大输液灌装机,西林瓶灌装机-长沙一星制药机械有限公司 | 高楼航空障碍灯厂家哪家好_航空障碍灯厂家_广州北斗星障碍灯有限公司 | 集装袋吨袋生产厂家-噸袋廠傢-塑料编织袋-纸塑复合袋-二手吨袋-太空袋-曹县建烨包装 | 施工围挡-施工PVC围挡-工程围挡-深圳市旭东钢构技术开发有限公司 | 玉米加工设备,玉米深加工机械,玉米糁加工设备.玉米脱皮制糁机 华豫万通粮机 | 航空障碍灯_高中低光强航空障碍灯_民航许可认证航空警示灯厂家-东莞市天翔航天科技有限公司 | 路斯特伺服驱动器维修,伦茨伺服驱动器维修|万骏自动化百科 | 机床主轴维修|刀塔维修|C轴维修-常州翔高精密机械有限公司 | 高扬程排污泵_隔膜泵_磁力泵_节能自吸离心水泵厂家-【上海博洋】 | 无水硫酸铝,硫酸铝厂家-淄博双赢新材料科技有限公司 | 外贮压-柜式-悬挂式-七氟丙烷-灭火器-灭火系统-药剂-价格-厂家-IG541-混合气体-贮压-非贮压-超细干粉-自动-灭火装置-气体灭火设备-探火管灭火厂家-东莞汇建消防科技有限公司 | 青州开防盗门锁-配汽车芯片钥匙-保险箱钥匙-吉祥修锁店 | 【化妆品备案】进口化妆品备案流程-深圳美尚美化妆品有限公司 | 高低温万能试验机_拉力试验机_拉伸试验机-馥勒仪器科技(上海)有限公司 | LCD3D打印机|教育|桌面|光固化|FDM3D打印机|3D打印设备-广州造维科技有限公司 | 餐饮加盟网_特色餐饮连锁加盟店-餐饮加盟官网 | 除湿机|工业除湿机|抽湿器|大型地下室车间仓库吊顶防爆除湿机|抽湿烘干房|新风除湿机|调温/降温除湿机|恒温恒湿机|加湿机-杭州川田电器有限公司 | 爆炸冲击传感器-无线遥测传感器-航天星百科 | 泰兴市热钻机械有限公司-热熔钻孔机-数控热熔钻-热熔钻孔攻牙一体机 | 数码听觉统合训练系统-儿童感觉-早期言语评估与训练系统-北京鑫泰盛世科技发展有限公司 | 空气能采暖,热泵烘干机,空气源热水机组|设备|厂家,东莞高温热泵_正旭新能源 | 小青瓦丨古建筑瓦丨青瓦厂家-宜兴市徽派古典建筑材料有限公司 | 小型单室真空包装机,食品单室真空包装机-百科 | 低浓度恒温恒湿称量系统,强光光照培养箱-上海三腾仪器有限公司 | 苗木价格-苗木批发-沭阳苗木基地-沭阳花木-长之鸿园林苗木场 |