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

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

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

    2. <legend id='zZdBY'><style id='zZdBY'><dir id='zZdBY'><q id='zZdBY'></q></dir></style></legend>

      multiprocessing.Pool - PicklingError: Can't pickle &l

      multiprocessing.Pool - PicklingError: Can#39;t pickle lt;type #39;thread.lock#39;gt;: attribute lookup thread.lock failed(multiprocessing.Pool - PicklingError: Cant pickle lt;type thread.lockgt;: 屬性查找 thread.lock 失敗) - IT屋-程序

    3. <small id='tbxlR'></small><noframes id='tbxlR'>

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

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

            • <bdo id='tbxlR'></bdo><ul id='tbxlR'></ul>
              <tfoot id='tbxlR'></tfoot>
                  <tbody id='tbxlR'></tbody>
                本文介紹了multiprocessing.Pool - PicklingError: Can't pickle &lt;type 'thread.lock'&gt;: 屬性查找 thread.lock 失敗的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                multiprocessing.Pool 快把我逼瘋了...
                我想升級許多軟件包,并且對于每個軟件包,我都必須檢查是否有更高版本.這是由 check_one 函數完成的.
                主要代碼在 Updater.update 方法中:在那里我創建了 Pool 對象并調用 map() 方法.

                multiprocessing.Pool is driving me crazy...
                I want to upgrade many packages, and for every one of them I have to check whether there is a greater version or not. This is done by the check_one function.
                The main code is in the Updater.update method: there I create the Pool object and call the map() method.

                代碼如下:

                def check_one(args):
                    res, total, package, version = args
                    i = res.qsize()
                    logger.info('
                [{0:.1%} - {1}, {2} / {3}]',
                        i / float(total), package, i, total, addn=False)
                    try:
                        json = PyPIJson(package).retrieve()
                        new_version = Version(json['info']['version'])
                    except Exception as e:
                        logger.error('Error: Failed to fetch data for {0} ({1})', package, e)
                        return
                    if new_version > version:
                        res.put_nowait((package, version, new_version, json))
                
                class Updater(FileManager):
                
                    # __init__ and other methods...
                
                    def update(self):    
                        logger.info('Searching for updates')
                        packages = Queue.Queue()
                        data = ((packages, self.set_len, dist.project_name, Version(dist.version)) 
                            for dist in self.working_set)
                        pool = multiprocessing.Pool()
                        pool.map(check_one, data)
                        pool.close()
                        pool.join()
                        while True:
                            try:
                                package, version, new_version, json = packages.get_nowait()
                            except Queue.Empty:
                                break
                            txt = 'A new release is avaiable for {0}: {1!s} (old {2}), update'.format(package,
                                                                                                      new_version,
                                                                                                      version)
                            u = logger.ask(txt, bool=('upgrade version', 'keep working version'), dont_ask=self.yes)
                            if u:
                                self.upgrade(package, json, new_version)
                            else:
                                logger.info('{0} has not been upgraded', package)
                        self._clean()
                        logger.success('Updating finished successfully')
                

                當我運行它時,我得到了這個奇怪的錯誤:

                When I run it I get this weird error:

                Searching for updates
                Exception in thread Thread-1:
                Traceback (most recent call last):
                  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
                    self.run()
                  File "/usr/lib/python2.7/threading.py", line 505, in run
                    self.__target(*self.__args, **self.__kwargs)
                  File "/usr/local/lib/python2.7/dist-packages/multiprocessing/pool.py", line 225, in _handle_tasks
                    put(task)
                PicklingError: Can't pickle <type 'thread.lock'>: attribute lookup thread.lock failed
                

                推薦答案

                multiprocessing 通過 將任務(包括 check_onedata)傳遞給工作進程mp.SimpleQueue.與 Queue.Queue 不同,放在 mp.SimpleQueue 中的所有內容都必須是可選擇的.Queue.Queues 是不可挑選的:

                multiprocessing passes tasks (which include check_one and data) to the worker processes through a mp.SimpleQueue. Unlike Queue.Queues, everything put in the mp.SimpleQueue must be pickable. Queue.Queues are not pickable:

                import multiprocessing as mp
                import Queue
                
                def foo(queue):
                    pass
                
                pool=mp.Pool()
                q=Queue.Queue()
                
                pool.map(foo,(q,))
                

                產生此異常:

                UnpickleableError: Cannot pickle <type 'thread.lock'> objects
                

                您的 data 包括 packages,這是一個 Queue.Queue.這可能是問題的根源.

                Your data includes packages, which is a Queue.Queue. That might be the source of the problem.

                這是一個可能的解決方法:Queue 用于兩個目的:

                Here is a possible workaround: The Queue is being used for two purposes:

                1. 找出近似大小(通過調用qsize)
                2. 存儲結果以供日后檢索.

                我們可以使用 mp.Value,而不是調用 qsize,以便在多個進程之間共享一個值.

                Instead of calling qsize, to share a value between multiple processes, we could use a mp.Value.

                我們可以(并且應該)只返回來自對 check_one 的調用的值,而不是將結果存儲在隊列中.pool.map 將結果收集到自己制作的隊列中,并將結果作為 pool.map 的返回值返回.

                Instead of storing results in a queue, we can (and should) just return values from calls to check_one. The pool.map collects the results in a queue of its own making, and returns the results as the return value of pool.map.

                例如:

                import multiprocessing as mp
                import Queue
                import random
                import logging
                
                # logger=mp.log_to_stderr(logging.DEBUG)
                logger = logging.getLogger(__name__)
                
                
                qsize = mp.Value('i', 1)
                def check_one(args):
                    total, package, version = args
                    i = qsize.value
                    logger.info('
                [{0:.1%} - {1}, {2} / {3}]'.format(
                        i / float(total), package, i, total))
                    new_version = random.randrange(0,100)
                    qsize.value += 1
                    if new_version > version:
                        return (package, version, new_version, None)
                    else:
                        return None
                
                def update():    
                    logger.info('Searching for updates')
                    set_len=10
                    data = ( (set_len, 'project-{0}'.format(i), random.randrange(0,100))
                             for i in range(set_len) )
                    pool = mp.Pool()
                    results = pool.map(check_one, data)
                    pool.close()
                    pool.join()
                    for result in results:
                        if result is None: continue
                        package, version, new_version, json = result
                        txt = 'A new release is avaiable for {0}: {1!s} (old {2}), update'.format(
                            package, new_version, version)
                        logger.info(txt)
                    logger.info('Updating finished successfully')
                
                if __name__=='__main__':
                    logging.basicConfig(level=logging.DEBUG)
                    update()
                

                這篇關于multiprocessing.Pool - PicklingError: Can't pickle &lt;type 'thread.lock'&gt;: 屬性查找 thread.lock 失敗的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)
                • <bdo id='yphoE'></bdo><ul id='yphoE'></ul>
                • <tfoot id='yphoE'></tfoot>

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

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

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

                          主站蜘蛛池模板: 超级乱淫av片免费播放 | 在线精品国产 | 亚洲精品一区二区冲田杏梨 | 日韩欧美国产一区二区 | 久久久精彩视频 | 成人午夜在线视频 | 日韩精品极品视频在线观看免费 | 黄色一级视频 | 色婷婷亚洲一区二区三区 | 日日操操 | 日韩一区二区在线观看视频 | 波多野结衣一区二区三区在线观看 | 黄色av免费| 一级片aaa | 欧美在线国产精品 | 国产乱码精品一区二区三区中文 | 国产美女免费视频 | 在线观看中文字幕视频 | 国产精品一区二区欧美黑人喷潮水 | 国产探花在线精品一区二区 | 日韩在线第一 | 欧美视频中文字幕 | 亚洲国产成人精品在线 | 久久久免费少妇高潮毛片 | 99影视 | 日韩av免费在线观看 | 日韩欧美三级电影 | 91精品中文字幕一区二区三区 | 91精品国产综合久久香蕉922 | 亚洲综合视频 | www.久| 午夜影院在线免费观看视频 | 精品一区二区三区不卡 | 奇米久久久 | 日韩国产精品一区二区三区 | 久草色视频 | 免费黄网站在线观看 | 人妖videosex高潮另类 | 三级特黄特色视频 | 亚洲精久久久 | 风间由美一区二区三区在线观看 |