久久久久久久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賬號..

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

                  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()?

                  推薦答案

                  初始化函數(shù)是這樣調用的:

                  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 = ...
                  

                  現(xiàn)在您可以在 process_data 函數(shù)中使用 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模板網(wǎng)!

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

                  相關文檔推薦

                  What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                  Passing multiple parameters to pool.map() function in Python(在 Python 中將多個參數(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 多進程池.當其中一個工作進程確定不再需要完成工作時,如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊列引用傳遞給 pool.map_async() 管理的函數(shù)?)
                  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>
                          • 主站蜘蛛池模板: 秋霞影院一区二区 | 性色的免费视频 | 国产一区免费 | 精品国产一区二区国模嫣然 | 天天干狠狠操 | www.夜夜草 | 一区二区精品视频 | 羞羞视频免费在线观看 | 国产精品色一区二区三区 | 黄色在线免费看 | 黄色网址免费在线观看 | av在线播放国产 | 日本不卡一区二区三区在线观看 | 伊人中文网| 99精品免费久久久久久久久日本 | 亚洲综合二区 | 一区二区三区在线 | 欧 | 毛片免费看的 | 中文字幕av中文字幕 | 亚洲一区二区精品视频 | 精品成人免费一区二区在线播放 | 日日骚网| 国产精品久久av | www.久久 | 久久精品网 | 日韩电影免费在线观看中文字幕 | 福利在线观看 | 黄网站涩免费蜜桃网站 | 国产一区二区三区视频在线观看 | 欧美成人a∨高清免费观看 色999日韩 | 久久伊人亚洲 | 国产在线网址 | 欧美日韩精品一区二区 | 中文字幕一区二区三区四区 | 黄网在线观看 | 亚洲精品久久久久久久久久久 | 一区二区三区视频在线观看 | 亚洲精品久久嫩草网站秘色 | 四虎影院在线免费观看 | 免费视频中文字幕 | a级免费黄色片 |