久久久久久久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 多處理的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  可能重復:
                  Python 多處理全局變量更新未返回給父級

                  我正在使用具有多個內核的計算機,為了提高性能,我真的應該使用多個內核.但是,我很困惑為什么這些代碼沒有達到我的預期:

                  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
                  

                  我希望結果是 [1, 2, 3, 4, 5] 但結果是 [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].

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

                  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?

                  推薦答案

                  如果您正在運行兩個單獨的進程,那么它們將不會共享相同的全局變量.如果要在進程之間傳遞數據,請查看使用 send 和 recv.看看 http://docs.python.org/library/multiprocessing.html#shared-state-between-processes 舉一個與您正在做的類似的例子.

                  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.

                  這篇關于全局變量和 Python 多處理的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
                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>

                            主站蜘蛛池模板: 一区二区三区免费 | 国产激情 | 精品一区精品二区 | 毛片免费观看 | 欧美日韩不卡在线 | 久久av一区二区 | 在线观看成人 | 日韩视频成人 | 欧洲高清转码区一二区 | 91色视频在线观看 | 国产精品久久久久久久一区探花 | 日韩精品一区二区三区视频播放 | 亚洲欧美日韩系列 | 美女一级a毛片免费观看97 | 久久成人国产精品 | 97精品一区二区 | 国产一区二区三区四区在线观看 | 91精品国产乱码麻豆白嫩 | 日韩福利一区 | 1级毛片 | 久久久高清 | 伊人一二三 | 亚洲va欧美va天堂v国产综合 | 亚洲高清一区二区三区 | 超碰av在线 | 亚洲综合色视频在线观看 | 久久久蜜臀国产一区二区 | 国产成人精品免费视频 | 99re6热在线精品视频播放 | 亚洲一区二区三区四区视频 | www.三级| 国产精品a久久久久 | 亚洲国产精品一区二区三区 | 久久久久久女 | 精品一二三区视频 | 日本一本视频 | 欧美男男videos | 视频精品一区二区三区 | 成人免费视频观看视频 | 中文一区二区 | 日韩激情一区 |