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

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

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

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

      1. 如何殺死多進程中的所有池工作人員?

        How to kill all Pool workers in multiprocess?(如何殺死多進程中的所有池工作人員?)

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

        <tfoot id='jhTBy'></tfoot>
          <tbody id='jhTBy'></tbody>

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

          • <bdo id='jhTBy'></bdo><ul id='jhTBy'></ul>

              <i id='jhTBy'><tr id='jhTBy'><dt id='jhTBy'><q id='jhTBy'><span id='jhTBy'><b id='jhTBy'><form id='jhTBy'><ins id='jhTBy'></ins><ul id='jhTBy'></ul><sub id='jhTBy'></sub></form><legend id='jhTBy'></legend><bdo id='jhTBy'><pre id='jhTBy'><center id='jhTBy'></center></pre></bdo></b><th id='jhTBy'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='jhTBy'><tfoot id='jhTBy'></tfoot><dl id='jhTBy'><fieldset id='jhTBy'></fieldset></dl></div>
                • 本文介紹了如何殺死多進程中的所有池工作人員?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我想停止單個工作人員的所有線程.

                  I want to stop all threads from a single worker.

                  我有一個有 10 個工人的線程池:

                  I have a thread pool with 10 workers:

                  def myfunction(i):
                      print(i) 
                      if (i == 20):
                          sys.exit()
                  
                  p = multiprocessing.Pool(10, init_worker) 
                  
                  for i in range(100):
                      p.apply_async(myfunction, (i,))
                  

                  我的程序不會停止,其他進程會繼續工作,直到完成所有 100 次迭代.我想完全從調用 sys.exit() 的線程內部停止池.目前的寫法只會停止調用sys.exit()的worker.

                  My program does not stop and the other processes continue working until all 100 iterations are complete. I want to stop the pool entirely from inside the thread that calls sys.exit(). The way it is currently written will only stop the worker that calls sys.exit().

                  推薦答案

                  這不是你想要的方式,因為在工作進程中調用 sys.exit() 只會終止工人.它對父進程或其他工作進程沒有影響,因為它們是獨立的進程,提高 SystemExit 只會影響當前進程.您需要向父進程發送一個信號,告訴它應該關閉.為您的用例執行此操作的一種方法是使用 Eventmultiprocessing.Manager 服務器:

                  This isn't working the way you're intending because calling sys.exit() in a worker process will only terminate the worker. It has no effect on the parent process or the other workers, because they're separate processes and raising SystemExit only affects the current process. You need to send a signal back the parent process to tell it that it should shut down. One way to do this for your use-case would be to use an Event created in a multiprocessing.Manager server:

                  import multiprocessing
                  
                  def myfunction(i, event):
                      if not event.is_set():
                          print i 
                      if i == 20:
                          event.set()
                  
                  if __name__ == "__main__":
                      p= multiprocessing.Pool(10) 
                      m = multiprocessing.Manager()
                      event = m.Event()
                      for i in range(100):
                          p.apply_async(myfunction , (i, event))
                      p.close()
                  
                      event.wait()  # We'll block here until a worker calls `event.set()`
                      p.terminate() # Terminate all processes in the Pool
                  

                  輸出:

                  0
                  1
                  2
                  3
                  4
                  5
                  6
                  7
                  8
                  9
                  10
                  11
                  12
                  13
                  14
                  15
                  16
                  17
                  18
                  19
                  20
                  

                  正如 Luke 的回答中所指出的,這里有一場競賽:不能保證所有工作人員都會按順序運行,因此 myfunction(20, ..) 可能會在之前運行例如,myfuntion(19, ..).20 之后的其他工作人員也可能在主進程可以對正在設置的事件采取行動之前運行.我通過在打印 i 之前添加 if not event.is_set(): 調用來減小比賽窗口的大小,但它仍然存在.

                  As pointed out in Luke's answer, there is a race here: There's no guarantee that all the workers will run in order, so it's possible that myfunction(20, ..) will run prior to myfuntion(19, ..), for example. It's also possible that other workers after 20 will run before the main process can act on the event being set. I reduced the size of the race window by adding the if not event.is_set(): call prior to printing i, but it still exists.

                  這篇關于如何殺死多進程中的所有池工作人員?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
                • <tfoot id='S4E2e'></tfoot>

                    1. <small id='S4E2e'></small><noframes id='S4E2e'>

                      • <legend id='S4E2e'><style id='S4E2e'><dir id='S4E2e'><q id='S4E2e'></q></dir></style></legend>

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

                            主站蜘蛛池模板: 福利网址 | 日本午夜免费福利视频 | 久久久久久久av | 国产一区二区不卡 | 久久久久久艹 | 久久久www成人免费无遮挡大片 | 黑人巨大精品欧美一区二区一视频 | 亚洲天天干 | 国产丝袜av | a在线观看 | 亚洲a在线观看 | 亚洲综合大片69999 | 精品久久久精品 | 久久久新视频 | 综合色在线 | 成年免费大片黄在线观看岛国 | 欧美毛片免费观看 | 日韩手机在线看片 | 五月婷六月丁香 | 日韩欧美在线免费观看视频 | 国产精品不卡视频 | 99在线国产| 色免费视频 | 中文字幕二区三区 | 欧美日韩中文国产一区发布 | 日韩免费1区二区电影 | 黄色成人免费看 | 欧美激情在线精品一区二区三区 | 亚州中文 | 日韩欧美在线视频播放 | 欧美日韩久久久 | 亚洲成人一区二区 | 国产一级片免费视频 | 久久大 | 国产亚洲成av人片在线观看桃 | 日韩第一页| 精品国产欧美一区二区三区成人 | 欧洲毛片| 人碰人操| 国产精品久久久久久久久免费丝袜 | 在线资源视频 |