久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

      1. <small id='8Bhpv'></small><noframes id='8Bhpv'>

      2. <tfoot id='8Bhpv'></tfoot>

          <bdo id='8Bhpv'></bdo><ul id='8Bhpv'></ul>

        全局變量和 Python 多處理

        Globals variables and Python multiprocessing(全局變量和 Python 多處理)
          <i id='uGUIn'><tr id='uGUIn'><dt id='uGUIn'><q id='uGUIn'><span id='uGUIn'><b id='uGUIn'><form id='uGUIn'><ins id='uGUIn'></ins><ul id='uGUIn'></ul><sub id='uGUIn'></sub></form><legend id='uGUIn'></legend><bdo id='uGUIn'><pre id='uGUIn'><center id='uGUIn'></center></pre></bdo></b><th id='uGUIn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='uGUIn'><tfoot id='uGUIn'></tfoot><dl id='uGUIn'><fieldset id='uGUIn'></fieldset></dl></div>

              <bdo id='uGUIn'></bdo><ul id='uGUIn'></ul>
                <tbody id='uGUIn'></tbody>

                  <tfoot id='uGUIn'></tfoot>

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

                  <legend id='uGUIn'><style id='uGUIn'><dir id='uGUIn'><q id='uGUIn'></q></dir></style></legend>
                1. 本文介紹了全局變量和 Python 多處理的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

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

                  可能重復(fù):
                  Python 多處理全局變量更新未返回給父級(jí)

                  我正在使用具有多個(gè)內(nèi)核的計(jì)算機(jī),為了提高性能,我真的應(yīng)該使用多個(gè)內(nèi)核.但是,我很困惑為什么這些代碼沒(méi)有達(dá)到我的預(yù)期:

                  I am using a computer with many cores and for performance benefits I should really use more than one. However, I'm confused why these bits of code don't do what I expect:

                  from multiprocessing import Process
                  
                  var = range(5)
                  def test_func(i):
                      global var
                      var[i] += 1
                  
                  if __name__ == '__main__':
                      jobs = []
                      for i in xrange(5):
                          p = Process(target=test_func,args=(i,))
                          jobs.append(p)
                          p.start()
                  
                  print var
                  

                  還有

                  from multiprocessing import Pool
                  
                  var = range(5)
                  def test_func(i):
                      global var
                      var[i] += 1
                  
                  if __name__ == '__main__':
                      p = Pool()
                      for i in xrange(5):
                          p.apply_async(test_func,[i])
                  
                  print var
                  

                  我希望結(jié)果是 [1, 2, 3, 4, 5] 但結(jié)果是 [0, 1, 2, 3, 4].

                  I expect the result to be [1, 2, 3, 4, 5] but the result is [0, 1, 2, 3, 4].

                  在將全局變量與進(jìn)程一起使用時(shí),我肯定遺漏了一些微妙之處.這甚至是要走的路還是我應(yīng)該避免嘗試以這種方式更改變量?

                  There must be some subtlety I'm missing in using global variables with processes. Is this even the way to go or should I avoid trying to change a variable in this manner?

                  推薦答案

                  如果您正在運(yùn)行兩個(gè)單獨(dú)的進(jìn)程,那么它們將不會(huì)共享相同的全局變量.如果要在進(jìn)程之間傳遞數(shù)據(jù),請(qǐng)查看使用 send 和 recv.看看 http://docs.python.org/library/multiprocessing.html#shared-state-between-processes 舉一個(gè)與您正在做的類(lèi)似的例子.

                  If you are running two separate processes, then they won't be sharing the same globals. If you want to pass the data between the processes, look at using send and recv. Take a look at http://docs.python.org/library/multiprocessing.html#sharing-state-between-processes for an example similar to what you're doing.

                  這篇關(guān)于全局變量和 Python 多處理的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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屋-程序員軟件開(kāi)
                  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è)混淆,“模塊對(duì)象沒(méi)有屬性“f)
                2. <tfoot id='qUPLC'></tfoot>

                      <bdo id='qUPLC'></bdo><ul id='qUPLC'></ul>
                          <tbody id='qUPLC'></tbody>

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

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

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

                            主站蜘蛛池模板: 激情三区 | 欧美成人h版在线观看 | 黄色一级大片在线免费看产 | 国产精品不卡一区 | 久草免费福利 | 亚洲黄色一区二区三区 | 青青草av网站 | 久久精品99| 一区二区三区四区在线 | 精品视频免费 | 午夜电影在线播放 | 日韩欧美一区二区三区免费观看 | 国产精品久久久久久久久久久久冷 | 国产精品久久久久久久久久久久冷 | 国产精品区二区三区日本 | 久久久久久国产精品免费免费狐狸 | 四虎永久免费黄色影片 | 中文字幕乱码一区二区三区 | 国产精品免费一区二区三区四区 | 久久伊人精品 | 国产亚洲精品成人av久久ww | 一本一道久久a久久精品综合蜜臀 | wwwww在线观看 | 欧美精品v国产精品v日韩精品 | 九九久久久| 中文一区| 国产99久久久国产精品 | 精品国产乱码久久久久久图片 | 婷婷综合 | 日韩一级免费大片 | 国产精品久久久乱弄 | 日韩视频国产 | 伊人二区| 久久天堂 | av永久免费 | 日韩人体视频 | 精品视频一区二区三区 | 干干干日日日 | 人人插人人 | av天天看| 久久精品国产精品青草 |