久久久久久久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浪潮av | 可以免费看黄的网站 | 久久精品欧美一区二区三区不卡 | 亚洲成色www.777999 | 精品一区在线播放 | 一本不卡| 成人在线免费观看网站 | 亚洲精品91天天久久人人 | 国内精品视频在线观看 | 中文久久久 | 久久久国产精品人人片 | 曰本毛茸茸性生活 | 日韩天堂网 | 久久精品久久久久久久 | 色av网| 日韩a视频 | 日韩a在线 | 午夜a级片 | 日韩图色 | av网站免费看 | 中文字字幕在线中文 | 国产一级片免费观看 | 久久精品免费看 | 亚洲经典一区二区 | 国产精品欧美激情 | 日韩成人片 | 欧美成人精品一区二区三区在线看 | 玉足女爽爽91 | 狠狠se | 伊人网视频 | 欧美夜夜操 | 国产精品入口66mio男同 | 亚洲免费观看 | 国产精品国产三级国产 | 爱啪啪av| 97视频在线观看免费 | 日韩二三区 | 午夜在线影院 | 国产激情在线视频 | 国产吃瓜黑料一区二区 | 精品视频在线免费观看 |