久久久久久久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. 帶有工作進(jìn)程的 python 池

      python Pool with worker Processes(帶有工作進(jìn)程的 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>
                本文介紹了帶有工作進(jìn)程的 python 池的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                限時(shí)送ChatGPT賬號(hào)..

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

                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)
                

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

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

                推薦答案

                我建議你為此使用隊(duì)列.

                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
                

                現(xiàn)在您可以開始一堆這些,所有這些都從一個(gè)隊(duì)列中獲取工作

                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) 
                

                這樣的事情應(yīng)該可以讓您將昂貴的啟動(dòng)成本分?jǐn)偨o多個(gè)工人.

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

                這篇關(guān)于帶有工作進(jìn)程的 python 池的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                Passing multiple parameters to pool.map() function in Python(在 Python 中將多個(gè)參數(shù)傳遞給 pool.map() 函數(shù))
                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 多進(jìn)程池.當(dāng)其中一個(gè)工作進(jìn)程確定不再需要完成工作時(shí),如何退出腳本?) - IT屋-程序員
                How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊(duì)列引用傳遞給 pool.map_async() 管理的函數(shù)?)
                yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯(cuò)誤的另一個(gè)混淆,“模塊對(duì)象沒有屬性“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>
                          主站蜘蛛池模板: 久久国产欧美日韩精品 | 国产成人高清成人av片在线看 | 国产中文 | 99久久久99久久国产片鸭王 | 日韩一区二区在线视频 | 精品亚洲永久免费精品 | www.887色视频免费 | 精品久久久久久国产 | 麻豆视频在线免费观看 | 91最新入口| 中文天堂在线观看 | 亚洲精品一级 | 国产高清在线精品一区二区三区 | 欧美一区二区三区在线观看 | 亚洲成人精品 | 视频在线观看亚洲 | 91精品国产91久久久久青草 | 国产欧美一区二区精品忘忧草 | 99热这里 | 欧美一级免费看 | www.一级毛片 | 秋霞在线一区二区 | 久久精品亚洲欧美日韩精品中文字幕 | 福利视频三区 | 盗摄精品av一区二区三区 | 日韩一二三 | 亚洲激情网站 | 91久久精品国产免费一区 | 亚洲国产成人久久久 | 精品一区二区视频 | 在线观看视频一区二区三区 | 337p日韩| 欧美日韩a| 亚洲成人久久久 | 99re6在线视频 | 日本在线小视频 | 亚洲一一在线 | 久久不卡区 | 久久亚 | 精品国产一区二区三区久久久蜜月 | 99在线资源 |