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

    <tfoot id='hMVQs'></tfoot>

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

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

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

        <bdo id='hMVQs'></bdo><ul id='hMVQs'></ul>

    2. 帶有工作進程的 python 池

      python Pool with worker Processes(帶有工作進程的 python 池)
    3. <small id='EpdlS'></small><noframes id='EpdlS'>

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

            <bdo id='EpdlS'></bdo><ul id='EpdlS'></ul>

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

                問題描述

                限時送ChatGPT賬號..

                我正在嘗試使用進程對象在 python 中使用工作池.每個工人(一個進程)進行一些初始化(花費大量時間),傳遞一系列作業(理想情況下使用 map()),并返回一些東西.除此之外,不需要任何溝通.但是,我似乎無法弄清楚如何使用 map() 來使用我的工人的 compute() 函數.

                I am trying to use a worker Pool in python using Process objects. Each worker (a Process) does some initialization (takes a non-trivial amount of time), gets passed a series of jobs (ideally using map()), and returns something. No communication is necessary beyond that. However, I can't seem to figure out how to use map() to use my worker's compute() function.

                from multiprocessing import Pool, Process
                
                class Worker(Process):
                    def __init__(self):
                        print 'Worker started'
                        # do some initialization here
                        super(Worker, self).__init__()
                
                    def compute(self, data):
                        print 'Computing things!'
                        return data * data
                
                if __name__ == '__main__':
                    # This works fine
                    worker = Worker()
                    print worker.compute(3)
                
                    # workers get initialized fine
                    pool = Pool(processes = 4,
                                initializer = Worker)
                    data = range(10)
                    # How to use my worker pool?
                    result = pool.map(compute, data)
                

                是作業隊列代替,還是我可以使用 map()?

                Is a job queue the way to go instead, or can I use map()?

                推薦答案

                我建議你為此使用隊列.

                I would suggest that you use a Queue for this.

                class Worker(Process):
                    def __init__(self, queue):
                        super(Worker, self).__init__()
                        self.queue = queue
                
                    def run(self):
                        print('Worker started')
                        # do some initialization here
                
                        print('Computing things!')
                        for data in iter(self.queue.get, None):
                            # Use data
                

                現在您可以開始一堆這些,所有這些都從一個隊列中獲取工作

                Now you can start a pile of these, all getting work from a single queue

                request_queue = Queue()
                for i in range(4):
                    Worker(request_queue).start()
                for data in the_real_source:
                    request_queue.put(data)
                # Sentinel objects to allow clean shutdown: 1 per worker.
                for i in range(4):
                    request_queue.put(None) 
                

                這樣的事情應該可以讓您將昂貴的啟動成本分攤給多個工人.

                That kind of thing should allow you to amortize the expensive startup cost across multiple workers.

                這篇關于帶有工作進程的 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)

                    <legend id='8Y53R'><style id='8Y53R'><dir id='8Y53R'><q id='8Y53R'></q></dir></style></legend>
                    • <bdo id='8Y53R'></bdo><ul id='8Y53R'></ul>

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

                      • <small id='8Y53R'></small><noframes id='8Y53R'>

                          <tbody id='8Y53R'></tbody>

                        • <tfoot id='8Y53R'></tfoot>
                          主站蜘蛛池模板: 日韩国产中文字幕 | 欧美一级在线免费观看 | 国产精品久久国产精品 | 亚洲品质自拍视频网站 | 韩日在线 | 国产毛片久久久久久久久春天 | 欧州一区二区三区 | 91最新在线视频 | 日韩另类视频 | 国产一级电影网 | 一区二区三区四区视频 | 在线国产99| 欧产日产国产精品视频 | 精品二区| 视频一区在线观看 | 国产网站在线播放 | 国产精品国产精品 | 精品在线免费观看视频 | 国内久久| 日本精品一区二区三区在线观看 | 亚洲午夜在线 | 精品久久久一区 | 成人精品一区二区 | 极品电影院 | 色综合区 | 最新中文字幕第一页视频 | 中文字幕精品一区久久久久 | 久草在线 | 亚洲一区二区三区视频 | 亚洲精品一区在线观看 | 成人在线黄色 | 一区二区三区精品在线 | 久久亚洲一区 | 91精品国产高清久久久久久久久 | 中文字幕一区二区三区日韩精品 | 国产亚洲一区二区精品 | 成人毛片视频在线播放 | 国产人成精品一区二区三 | 久久精品一区二区视频 | 国产露脸对白88av | 欧美1—12sexvideos |