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

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

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

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

        在 python 中填充隊列和管理多處理

        Filling a queue and managing multiprocessing in python(在 python 中填充隊列和管理多處理)

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

          • <bdo id='SdvrA'></bdo><ul id='SdvrA'></ul>
          • <legend id='SdvrA'><style id='SdvrA'><dir id='SdvrA'><q id='SdvrA'></q></dir></style></legend>
              • <tfoot id='SdvrA'></tfoot>

                1. <i id='SdvrA'><tr id='SdvrA'><dt id='SdvrA'><q id='SdvrA'><span id='SdvrA'><b id='SdvrA'><form id='SdvrA'><ins id='SdvrA'></ins><ul id='SdvrA'></ul><sub id='SdvrA'></sub></form><legend id='SdvrA'></legend><bdo id='SdvrA'><pre id='SdvrA'><center id='SdvrA'></center></pre></bdo></b><th id='SdvrA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='SdvrA'><tfoot id='SdvrA'></tfoot><dl id='SdvrA'><fieldset id='SdvrA'></fieldset></dl></div>
                    <tbody id='SdvrA'></tbody>
                  本文介紹了在 python 中填充隊列和管理多處理的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我在 python 中遇到了這個問題:

                  I'm having this problem in python:

                  • 我需要不時檢查的 URL 隊列
                  • 如果隊列已滿,我需要處理隊列中的每個項目
                  • 隊列中的每個項目都必須由單個進程處理(多處理)

                  到目前為止,我設法像這樣手動"實現了這一目標:

                  So far I managed to achieve this "manually" like this:

                  while 1:
                          self.updateQueue()
                  
                          while not self.mainUrlQueue.empty():
                              domain = self.mainUrlQueue.get()
                  
                              # if we didn't launched any process yet, we need to do so
                              if len(self.jobs) < maxprocess:
                                  self.startJob(domain)
                                  #time.sleep(1)
                              else:
                                  # If we already have process started we need to clear the old process in our pool and start new ones
                                  jobdone = 0
                  
                                  # We circle through each of the process, until we find one free ; only then leave the loop 
                                  while jobdone == 0:
                                      for p in self.jobs :
                                          #print "entering loop"
                                          # if the process finished
                                          if not p.is_alive() and jobdone == 0:
                                              #print str(p.pid) + " job dead, starting new one"
                                              self.jobs.remove(p)
                                              self.startJob(domain)
                                              jobdone = 1
                  

                  但是,這會導致大量問題和錯誤.我想知道我是否更適合使用進程池.這樣做的正確方法是什么?

                  However that leads to tons of problems and errors. I wondered if I was not better suited using a Pool of process. What would be the right way to do this?

                  但是,很多時候我的隊列是空的,一秒鐘可以填滿 300 個項目,所以我不太清楚這里該怎么做.

                  However, a lot of times my queue is empty, and it can be filled by 300 items in a second, so I'm not too sure how to do things here.

                  推薦答案

                  您可以使用 queue 在啟動時產生多個進程(使用 multiprocessing.Pool) 并讓它們休眠,直到隊列中有一些數據可供處理.如果您對此不熟悉,可以嘗試玩"用那個簡單的程序:

                  You could use the blocking capabilities of queue to spawn multiple process at startup (using multiprocessing.Pool) and letting them sleep until some data are available on the queue to process. If your not familiar with that, you could try to "play" with that simple program:

                  import multiprocessing
                  import os
                  import time
                  
                  the_queue = multiprocessing.Queue()
                  
                  
                  def worker_main(queue):
                      print os.getpid(),"working"
                      while True:
                          item = queue.get(True)
                          print os.getpid(), "got", item
                          time.sleep(1) # simulate a "long" operation
                  
                  the_pool = multiprocessing.Pool(3, worker_main,(the_queue,))
                  #                           don't forget the comma here  ^
                  
                  for i in range(5):
                      the_queue.put("hello")
                      the_queue.put("world")
                  
                  
                  time.sleep(10)
                  

                  在 Linux 上使用 Python 2.7.3 測試

                  這將產生 3 個進程(除了父進程).每個孩子都執行 worker_main 函數.這是一個簡單的循環,在每次迭代時從隊列中獲取一個新項目.如果沒有準備好處理,worker 將阻塞.

                  This will spawn 3 processes (in addition of the parent process). Each child executes the worker_main function. It is a simple loop getting a new item from the queue on each iteration. Workers will block if nothing is ready to process.

                  在啟動時,所有 3 個進程都將休眠,直到向隊列提供一些數據.當數據可用時,等待的工作人員之一獲得該項目并開始處理它.之后,它會嘗試從隊列中獲取其他項目,如果沒有可用則再次等待...

                  At startup all 3 process will sleep until the queue is fed with some data. When a data is available one of the waiting workers get that item and starts to process it. After that, it tries to get an other item from the queue, waiting again if nothing is available...

                  這篇關于在 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)

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

                        <small id='0d0a3'></small><noframes id='0d0a3'>

                      • <tfoot id='0d0a3'></tfoot>

                            <tbody id='0d0a3'></tbody>

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

                          2. 主站蜘蛛池模板: 国产成人综合在线 | 午夜精品久久久 | 中文字幕在线看人 | 成人片免费看 | 国产免费xxx | 久久久久久国产 | 日日综合 | 日本在线免费 | a级片网站 | 精品久久影院 | 久久综合一区 | 国产免费色| 99tv成人影院| 毛片在线看片 | 精品免费国产一区二区三区四区介绍 | 在线看片国产精品 | 99re免费 | 久久久久久久久国产精品 | 日韩欧美一区二区三区免费观看 | 日本成人中文字幕在线观看 | 黄视频网站在线 | 久久伊人在| 国产欧美一区二区三区免费 | 刘亦菲国产毛片bd | 日日夜精品视频 | 国产在线视频三区 | 久久av一区二区 | 成人在线精品视频 | 国产精品美女久久久 | 伊人春色在线观看 | 免费在线观看av网址 | 日韩aⅴ片 | 欧美色人 | 国产精品不卡 | 色婷婷av一区二区三区软件 | 国产精品久久久久久久久久免费看 | 国产精品久久久久久久一区二区 | 亚洲日韩中文字幕一区 | 精品久久久久久久人人人人传媒 | 成人性生交大免费 | 国产在线视频一区二区董小宛性色 |