久久久久久久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>

                            主站蜘蛛池模板: 久久久久久久免费视频 | 国产激情在线 | 欧美人xxxx | 另类专区亚洲 | 91亚洲成人 | 久久久久一区 | 中文字幕系列 | 色噜噜狠狠一区二区三区 | www.一区二区 | 成人综合网站 | 成人三级视频在线观看 | 一级黄色在线观看 | 日韩精品视频免费 | 久久久精品在线观看 | 午夜在线国语中文字幕视频 | 亚洲高清在线视频 | 久久久午夜 | 亚洲69视频 | 亚洲视频色| 天堂成人av | 精品一区二区三区视频 | 老司机深夜福利视频 | 一区二区三区日韩 | 黄色三级网 | 国产精品国产成人国产三级 | 国产三区在线观看 | 性欧美bbw | 国产亚洲欧美在线 | 丁香午夜| 成人av在线网站 | 在线天堂视频 | 国产理论在线 | 精品一区二区三区在线观看 | 一区二区三区日韩 | 国产伦精品一区二区三区视频我 | 欧美成视频| 黄色在线观看免费 | 无套内谢的新婚少妇国语播放 | 国产成人a亚洲精品 | 综合久久久久 | 九月色婷婷 |