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

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

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

        <bdo id='ghvlD'></bdo><ul id='ghvlD'></ul>
      <tfoot id='ghvlD'></tfoot>

        如何使用初始化程序來設置我的多進程池?

        how to use initializer to set up my multiprocess pool?(如何使用初始化程序來設置我的多進程池?)
        <i id='z9BPL'><tr id='z9BPL'><dt id='z9BPL'><q id='z9BPL'><span id='z9BPL'><b id='z9BPL'><form id='z9BPL'><ins id='z9BPL'></ins><ul id='z9BPL'></ul><sub id='z9BPL'></sub></form><legend id='z9BPL'></legend><bdo id='z9BPL'><pre id='z9BPL'><center id='z9BPL'></center></pre></bdo></b><th id='z9BPL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='z9BPL'><tfoot id='z9BPL'></tfoot><dl id='z9BPL'><fieldset id='z9BPL'></fieldset></dl></div>

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

              <tbody id='z9BPL'></tbody>

            1. <tfoot id='z9BPL'></tfoot>

                <bdo id='z9BPL'></bdo><ul id='z9BPL'></ul>
                1. <legend id='z9BPL'><style id='z9BPL'><dir id='z9BPL'><q id='z9BPL'></q></dir></style></legend>

                2. 本文介紹了如何使用初始化程序來設置我的多進程池?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在嘗試使用多進程池對象.我希望每個進程在啟動時打開一個數據庫連接,然后使用該連接來處理傳入的數據.(而不是為每一位數據打開和關閉連接.)這似乎是初始化程序對于,但我無法理解工作人員和初始化程序是如何通信的.所以我有這樣的事情:

                  I'm trying to use the multiprocess Pool object. I'd like each process to open a database connection when it starts, then use that connection to process the data that is passed in. (Rather than opening and closing the connection for each bit of data.) This seems like what the initializer is for, but I can't wrap my head around how the worker and the initializer communicate. So I have something like this:

                  def get_cursor():
                    return psycopg2.connect(...).cursor()
                  
                  def process_data(data):
                     # here I'd like to have the cursor so that I can do things with the data
                  
                  if __name__ == "__main__":
                    pool = Pool(initializer=get_cursor, initargs=())
                    pool.map(process_data, get_some_data_iterator())
                  

                  我如何(或我如何)將光標從 get_cursor() 取回 process_data()?

                  how do I (or do I) get the cursor back from get_cursor() into the process_data()?

                  推薦答案

                  初始化函數是這樣調用的:

                  The initialize function is called thus:

                  def worker(...):
                      ...
                      if initializer is not None:
                          initializer(*args)
                  

                  所以在任何地方都沒有保存返回值.你可能認為這注定了你的命運,但不是!每個工人都在一個單獨的進程中.因此,您可以使用普通的 global 變量.

                  so there is no return value saved anywhere. You might think this dooms you, but no! Each worker is in a separate process. Thus, you can use an ordinary global variable.

                  這不是很漂亮,但它確實有效:

                  This is not exactly pretty, but it works:

                  cursor = None
                  def set_global_cursor(...):
                      global cursor
                      cursor = ...
                  

                  現在您可以在 process_data 函數中使用 cursor.每個獨立進程內的cursor變量與所有其他進程是分開的,所以它們不會互相踩踏.

                  Now you can just use cursor in your process_data function. The cursor variable inside each separate process is separate from all the other processes, so they do not step on each other.

                  (我不知道 psycopg2 是否有不同的方法來處理這個問題,首先不涉及使用 multiprocessing;這是一個一般性的答案multiprocessing 模塊的一般問題.)

                  (I have no idea whether psycopg2 has a different way to deal with this that does not involve using multiprocessing in the first place; this is meant as a general answer to a general problem with the multiprocessing module.)

                  這篇關于如何使用初始化程序來設置我的多進程池?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
                3. <i id='4mneE'><tr id='4mneE'><dt id='4mneE'><q id='4mneE'><span id='4mneE'><b id='4mneE'><form id='4mneE'><ins id='4mneE'></ins><ul id='4mneE'></ul><sub id='4mneE'></sub></form><legend id='4mneE'></legend><bdo id='4mneE'><pre id='4mneE'><center id='4mneE'></center></pre></bdo></b><th id='4mneE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4mneE'><tfoot id='4mneE'></tfoot><dl id='4mneE'><fieldset id='4mneE'></fieldset></dl></div>

                        • <small id='4mneE'></small><noframes id='4mneE'>

                          <legend id='4mneE'><style id='4mneE'><dir id='4mneE'><q id='4mneE'></q></dir></style></legend>
                            <tbody id='4mneE'></tbody>
                            <bdo id='4mneE'></bdo><ul id='4mneE'></ul>
                            <tfoot id='4mneE'></tfoot>
                          • 主站蜘蛛池模板: 日韩欧美在线播放 | 国产中文在线 | 国产精品一级二级 | 国产精品日韩精品 | 国产精品3| 亚洲激情综合网 | 国产一区在线看 | 美女一级片 | 日韩av免费看 | 成人av免费看 | 日韩视频在线免费观看 | 四虎影视在线 | 成人免费av | 成人欧美视频 | 青青草视频网站 | 日韩视频第一页 | 久操av在线 | 四虎影院在线播放 | 久久久久久久网 | 亚洲第一天堂网 | 最新91视频| 成人动漫在线看 | 欧美日韩在线视频观看 | www.日本在线观看 | 中文字幕在线观看不卡 | 国产日韩欧美综合 | 亚洲天堂网在线观看 | 久久黄色网址 | 日韩欧美在线一区 | 国内自拍xxxx18| 久久久亚洲精品视频 | 夜夜欢视频 | 日韩av在线影院 | 国产精品福利在线 | 在线a视频 | 一区在线观看 | 国产女人18毛片18精品 | 久久精品欧美一区二区 | 伊人国产精品 | 日韩精品一区二区视频 | 91成人精品 |