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

    1. <legend id='KMIhb'><style id='KMIhb'><dir id='KMIhb'><q id='KMIhb'></q></dir></style></legend>

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

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

        多處理:在某些情況下,在賦值之前引用變量,但

        multiprocessing: variable being referenced before assignment in some cases but not others(多處理:在某些情況下,在賦值之前引用變量,但在其他情況下不引用)

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

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

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

            1. <tfoot id='G3elr'></tfoot>
                • 本文介紹了多處理:在某些情況下,在賦值之前引用變量,但在其他情況下不引用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我在這個網站的某個地方找到了以下示例:

                  I found the following example on this website somewhere:

                  import multiprocessing
                  import ctypes
                  import numpy as np
                  
                  shared_array_base = multiprocessing.Array(ctypes.c_double, 10*10)
                  shared_array = np.ctypeslib.as_array(shared_array_base.get_obj())
                  shared_array = shared_array.reshape(10, 10)
                  
                  # No copy was made
                  assert shared_array.base.base is shared_array_base.get_obj()
                  
                  # Parallel processing
                  def my_func(i, def_param=shared_array):
                      shared_array[i,:] = i
                  
                  if __name__ == '__main__':
                      pool = multiprocessing.Pool(processes=4)
                      pool.map(my_func, range(10))
                  
                      print shared_array
                  

                  上面的代碼工作正常,但是如果我想向共享數組添加一個數組,比如 shared_array += some_other_array (而不是上面的 shared_array[i,;] = i)我得到了

                  The above code works fine, but if I want to add an array to the shared array, something like shared_array += some_other_array (instead of the above shared_array[i,;] = i) I get

                  賦值前引用的局部變量shared_array"

                  local variable 'shared_array' referenced before assignment

                  任何想法為什么我不能這樣做?

                  Any ideas why I cannot do that?

                  推薦答案

                  如果一個變量被賦值給函數中的任何地方,它就會被視為一個局部變量.shared_array += some_other_array 等價于 shared_array = shared_array + some_other_array.因此 shared_array 被視為局部變量,當您嘗試在賦值右側使用它時,該變量并不存在.

                  If a variable is assigned to anywhere in a function, it is treated as a local variable. shared_array += some_other_array is equivalent to shared_array = shared_array + some_other_array. Thus shared_array is treated as a local variable, which does not exist at the time you try to use it on the right-hand side of the assignment.

                  如果你想使用全局 shared_array 變量,你需要通過在你的函數中放置一個 global shared_array 來顯式地將它標記為全局變量.

                  If you want to use the global shared_array variable, you need to explicitly mark it as global by putting a global shared_array in your function.

                  您沒有看到 shared_array[i,:] = i 錯誤的原因是它沒有分配給變量 shared_array.相反,它改變了該對象,分配給它的一部分.在 Python 中,分配給一個裸名(例如,shared_array = ...)與任何其他類型的分配(例如,shared_array[...] = ...),盡管它們看起來很相似.

                  The reason you don't see the error with shared_array[i,:] = i is that this does not assign to the variable shared_array. Rather, it mutates that object, assigning to a slice of it. In Python, assigning to a bare name (e.g., shared_array = ...) is very different from any other kind of assignment (e.g., shared_array[...] = ...), even though they look similar.

                  請注意,順便說一下,該錯誤與多處理無關.

                  Note, incidentally, that the error has nothing to do with multiprocessing.

                  這篇關于多處理:在某些情況下,在賦值之前引用變量,但在其他情況下不引用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)

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

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

                            主站蜘蛛池模板: 精品日韩欧美一区二区 | 操操网站 | 2021狠狠干 | a级免费视频 | 成人精品一区二区三区中文字幕 | 久久91av| 国产精品欧美一区二区三区 | 91精品国产91综合久久蜜臀 | 日韩欧美一区二区三区免费观看 | 日韩三级电影一区二区 | 久久久久久精 | 综合自拍| 99热在这里只有精品 | 超碰地址 | 在线视频一区二区 | 一区二区av在线 | 国产毛片毛片 | 国产伦精品一区二区三区视频金莲 | 亚洲精品一二三 | 国产精品无码永久免费888 | 黄色一级电影在线观看 | 久久久国产一区二区三区 | 在线看h| 亚洲成人国产 | 99久久亚洲 | 99re国产 | 成人免费视频网站在线观看 | 国产精品久久久久久久久久久久 | 亚洲狠狠丁香婷婷综合久久久 | a免费视频 | 国产日韩欧美中文字幕 | 中文字幕 欧美 日韩 | 黑人久久久 | 激情久久av一区av二区av三区 | 啪啪免费| 丝袜美腿一区二区三区 | 国产成人精品网站 | 欧美在线一区二区三区四区 | 国产日韩欧美在线 | 国产精品91视频 | 欧美性极品xxxx做受 |