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

    1. <tfoot id='95e5R'></tfoot>
      <i id='95e5R'><tr id='95e5R'><dt id='95e5R'><q id='95e5R'><span id='95e5R'><b id='95e5R'><form id='95e5R'><ins id='95e5R'></ins><ul id='95e5R'></ul><sub id='95e5R'></sub></form><legend id='95e5R'></legend><bdo id='95e5R'><pre id='95e5R'><center id='95e5R'></center></pre></bdo></b><th id='95e5R'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='95e5R'><tfoot id='95e5R'></tfoot><dl id='95e5R'><fieldset id='95e5R'></fieldset></dl></div>
    2. <legend id='95e5R'><style id='95e5R'><dir id='95e5R'><q id='95e5R'></q></dir></style></legend>
      • <bdo id='95e5R'></bdo><ul id='95e5R'></ul>
    3. <small id='95e5R'></small><noframes id='95e5R'>

        獲取python多處理池中worker的唯一ID

        Get a unique ID for worker in python multiprocessing pool(獲取python多處理池中worker的唯一ID)

        <tfoot id='lziem'></tfoot>
        1. <small id='lziem'></small><noframes id='lziem'>

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

                1. <legend id='lziem'><style id='lziem'><dir id='lziem'><q id='lziem'></q></dir></style></legend>
                  本文介紹了獲取python多處理池中worker的唯一ID的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  有沒有辦法為 python 多處理池中的每個工作人員分配一個唯一的 ID,以便池中特定工作人員運行的作業可以知道哪個工作人員正在運行它?根據文檔, Process 有一個 name 但是

                  Is there a way to assign each worker in a python multiprocessing pool a unique ID in a way that a job being run by a particular worker in the pool could know which worker is running it? According to the docs, a Process has a name but

                  名稱是一個僅用于識別目的的字符串.它沒有語義.多個進程可以被賦予相同的名稱.

                  The name is a string used for identification purposes only. It has no semantics. Multiple processes may be given the same name.

                  對于我的特定用例,我想在一組四個 GPU 上運行一堆作業,并且需要為應該運行作業的 GPU 設置設備號.因為作業的長度不均勻,所以我想確保在前一個作業完成之前嘗試在 GPU 上運行的作業不會在 GPU 上發生沖突(因此這排除了將 ID 預先分配給工作單元提前).

                  For my particular use-case, I want to run a bunch of jobs on a group of four GPUs, and need to set the device number for the GPU that the job should run on. Because the jobs are of non-uniform length, I want to be sure that I don't have a collision on a GPU of a job trying to run on it before the previous one completes (so this precludes pre-assigning an ID to the unit of work ahead of time).

                  推薦答案

                  看起來你想要的很簡單:multiprocessing.current_process().例如:

                  It seems like what you want is simple: multiprocessing.current_process(). For example:

                  import multiprocessing
                  
                  def f(x):
                      print multiprocessing.current_process()
                      return x * x
                  
                  p = multiprocessing.Pool()
                  print p.map(f, range(6))
                  

                  輸出:

                  $ python foo.py 
                  <Process(PoolWorker-1, started daemon)>
                  <Process(PoolWorker-2, started daemon)>
                  <Process(PoolWorker-3, started daemon)>
                  <Process(PoolWorker-1, started daemon)>
                  <Process(PoolWorker-2, started daemon)>
                  <Process(PoolWorker-4, started daemon)>
                  [0, 1, 4, 9, 16, 25]
                  

                  這會返回進程對象本身,因此進程可以是它自己的身份.您也可以在其上調用 id 以獲得唯一的數字 id ——在 cpython 中,這是進程對象的內存地址,所以我不認為有任何可能性的重疊.最后,您可以使用進程的 identpid 屬性——但這僅在進程啟動后設置.

                  This returns the process object itself, so the process can be its own identity. You could also call id on it for a unique numerical id -- in cpython, this is the memory address of the process object, so I don't think there's any possibility of overlap. Finally, you can use the ident or the pid property of the process -- but that's only set once the process is started.

                  此外,查看源代碼,在我看來,自動生成的名稱(如上面 Process repr 字符串中的第一個值所示)很可能是唯一的.multiprocessing 為每個進程維護一個 itertools.counter 對象,用于生成 _identity 元組用于它產生的任何子進程.因此頂級進程產生具有單值 id 的子進程,它們產生具有雙值 id 的進程,依此類推.然后,如果沒有名稱傳遞給 Process 構造函數,它只是 使用 ':'.join(...) 根據 _identity 自動生成名稱.然后 Pool 更改名稱使用 replace 處理,自動生成的 id 保持不變.

                  Furthermore, looking over the source, it seems to me very likely that autogenerated names (as exemplified by the first value in the Process repr strings above) are unique. multiprocessing maintains an itertools.counter object for every process, which is used to generate an _identity tuple for any child processes it spawns. So the top-level process produces child process with single-value ids, and they spawn process with two-value ids, and so on. Then, if no name is passed to the Process constructor, it simply autogenerates the name based on the _identity, using ':'.join(...). Then Pool alters the name of the process using replace, leaving the autogenerated id the same.

                  這一切的結果是雖然兩個Processes可能有相同的名字,因為你可能給它們分配了相同的名字創建它們時,如果您不觸摸 name 參數,它們是唯一的.此外,理論上您可以使用 _identity 作為唯一標識符;但我認為他們將這個變量設為私有是有原因的!

                  The upshot of all this is that although two Processes may have the same name, because you may assign the same name to them when you create them, they are unique if you don't touch the name parameter. Also, you could theoretically use _identity as a unique identifier; but I gather they made that variable private for a reason!

                  上面的一個例子:

                  import multiprocessing
                  
                  def f(x):
                      created = multiprocessing.Process()
                      current = multiprocessing.current_process()
                      print 'running:', current.name, current._identity
                      print 'created:', created.name, created._identity
                      return x * x
                  
                  p = multiprocessing.Pool()
                  print p.map(f, range(6))
                  

                  輸出:

                  $ python foo.py 
                  running: PoolWorker-1 (1,)
                  created: Process-1:1 (1, 1)
                  running: PoolWorker-2 (2,)
                  created: Process-2:1 (2, 1)
                  running: PoolWorker-3 (3,)
                  created: Process-3:1 (3, 1)
                  running: PoolWorker-1 (1,)
                  created: Process-1:2 (1, 2)
                  running: PoolWorker-2 (2,)
                  created: Process-2:2 (2, 2)
                  running: PoolWorker-4 (4,)
                  created: Process-4:1 (4, 1)
                  [0, 1, 4, 9, 16, 25]
                  

                  這篇關于獲取python多處理池中worker的唯一ID的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
                    <tbody id='s3Nv0'></tbody>
                  <legend id='s3Nv0'><style id='s3Nv0'><dir id='s3Nv0'><q id='s3Nv0'></q></dir></style></legend>

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

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

                            主站蜘蛛池模板: 先锋资源在线 | 精品视频一区在线 | 香蕉久久a毛片 | 免费观看黄网站 | 国产精品久久久久久久久久久久 | 情侣酒店偷拍一区二区在线播放 | 伊人免费视频二 | 成人国产精品久久久 | 羞羞视频在线观看网站 | 国产一区二区三区四区五区加勒比 | 欧美亚州综合 | 日韩a在线| 久久99国产精一区二区三区 | 91免费在线视频 | 91pao对白在线播放 | 成人午夜免费视频 | 久久国产精品一区二区三区 | 先锋资源网站 | 欧美日韩久久精品 | 中文字幕视频在线 | 免费看91 | 不卡一区二区三区四区 | 欧美成人激情 | 日韩成人在线观看 | 天天看片天天干 | 国产一区二区三区久久久久久久久 | 国产精品爱久久久久久久 | 免费黄色录像视频 | 欧美福利在线 | 国产精品成人69xxx免费视频 | 成人免费看片 | 综合二区 | 亚洲女人天堂成人av在线 | 91国内产香蕉 | 久久一久久 | 成人午夜av | 久久久精品亚洲 | 毛片a级 | 亚洲欧美中文日韩在线v日本 | 日韩精品久久久 | 在线中文字幕亚洲 |