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

  • <tfoot id='iWDZT'></tfoot>

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

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

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

        超出最大遞歸深度.多處理和 bs4

        Maximum recursion depth exceeded. Multiprocessing and bs4(超出最大遞歸深度.多處理和 bs4)

      2. <small id='URL8G'></small><noframes id='URL8G'>

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

              • <bdo id='URL8G'></bdo><ul id='URL8G'></ul>

                <tfoot id='URL8G'></tfoot>

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

                    <tbody id='URL8G'></tbody>
                  本文介紹了超出最大遞歸深度.多處理和 bs4的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在嘗試讓解析器使用 beautifulSoup 和多處理.我有一個錯誤:

                  I'm trying to make a parser use beautifulSoup and multiprocessing. I have an error:

                  RecursionError: 超出最大遞歸深度

                  RecursionError: maximum recursion depth exceeded

                  我的代碼是:

                  import bs4, requests, time
                  from multiprocessing.pool import Pool
                  
                  html = requests.get('https://www.avito.ru/moskva/avtomobili/bmw/x6?sgtd=5&radius=0')
                  soup = bs4.BeautifulSoup(html.text, "html.parser")
                  
                  divList = soup.find_all("div", {'class': 'item_table-header'})
                  
                  
                  def new_check():
                      with Pool() as pool:
                          pool.map(get_info, divList)
                  
                  def get_info(each):
                     pass
                  
                  if __name__ == '__main__':
                      new_check()
                  

                  為什么會出現此錯誤以及如何解決?

                  Why I get this error and how I can fix it?

                  更新:所有錯誤文本都是

                  Traceback (most recent call last):
                    File "C:/Users/eugen/PycharmProjects/avito/main.py", line 73, in <module> new_check()
                    File "C:/Users/eugen/PycharmProjects/avito/main.py", line 67, in new_check
                      pool.map(get_info, divList)
                    File "C:UserseugenAppDataLocalProgramsPythonPython36libmultiprocessingpool.py", line 266, in map
                      return self._map_async(func, iterable, mapstar, chunksize).get()
                    File "C:UserseugenAppDataLocalProgramsPythonPython36libmultiprocessingpool.py", line 644, in get
                      raise self._value
                    File "C:UserseugenAppDataLocalProgramsPythonPython36libmultiprocessingpool.py", line 424, in _handle_tasks
                      put(task)
                    File "C:UserseugenAppDataLocalProgramsPythonPython36libmultiprocessingconnection.py", line 206, in send
                      self._send_bytes(_ForkingPickler.dumps(obj))
                    File "C:UserseugenAppDataLocalProgramsPythonPython36libmultiprocessing
                  eduction.py", line 51, in dumps
                      cls(buf, protocol).dump(obj)
                  RecursionError: maximum recursion depth exceeded
                  

                  推薦答案

                  當你使用 multiprocessing 時,你傳遞給 worker 的所有東西都必須是 腌制.

                  When you use multiprocessing, everything you pass to a worker has to be pickled.

                  很遺憾,很多 BeautifulSoup 樹無法腌制.

                  Unfortunately, many BeautifulSoup trees can't be pickled.

                  這有幾個不同的原因.其中一些是已修復的錯誤,因此您可以嘗試確保您擁有最新的 bs4 版本,而有些則特定于不同的解析器或樹構建器......但很有可能沒有這樣的事情會有幫助的.

                  There are a few different reasons for this. Some of them are bugs that have since been fixed, so you could try making sure you have the latest bs4 version, and some are specific to different parsers or tree builders… but there's a good chance nothing like this will help.

                  但根本問題是樹中的許多元素都包含對樹其余部分的引用.

                  But the fundamental problem is that many elements in the tree contain references to the rest of the tree.

                  有時,這會導致實際的無限循環,因為循環引用對于其循環引用檢測來說過于間接.但這通常是一個可以修復的錯誤.

                  Occasionally, this leads to an actual infinite loop, because the circular references are too indirect for its circular reference detection. But that's usually a bug that gets fixed.

                  但是,更重要的是,即使循環不是無限,它仍然可以從樹的其余部分拖入 1000 多個元素,這已經足以導致遞歸錯誤.

                  But, even more importantly, even when the loop isn't infinite, it can still drag in more than 1000 elements from all over the rest of the tree, and that's already enough to cause a RecursionError.

                  我認為后者就是這里發生的事情.如果我使用您的代碼并嘗試腌制 divList[0],它會失敗.(如果我提高遞歸限制并計算幀數,它需要 23080 的深度,這遠遠超過默認的 1000.)但是如果我采用完全相同的 div 并解析分開,它成功沒有問題.

                  And I think the latter is what's happening here. If I take your code and try to pickle divList[0], it fails. (If I bump the recursion limit way up and count the frames, it needs a depth of 23080, which is way, way past the default of 1000.) But if I take that exact same div and parse it separately, it succeeds with no problem.

                  所以,一種可能性是只做 sys.setrecursionlimit(25000).這將解決這個確切頁面的問題,但是稍微不同的頁面可能需要更多.(另外,將遞歸限制設置得那么高通常不是一個好主意——不是因為浪費了內存,而是因為這意味著實際的無限遞歸需要 25 倍的時間和 25 倍的資源浪費來檢測.)

                  So, one possibility is to just do sys.setrecursionlimit(25000). That will solve the problem for this exact page, but a slightly different page might need even more than that. (Plus, it's usually not a great idea to set the recursion limit that high—not so much because of the wasted memory, but because it means actual infinite recursion takes 25x as long, and 25x as much wasted resources, to detect.)

                  另一個技巧是編寫修剪樹"的代碼,在您腌制之前/之后消除 div 中的任何向上鏈接.這是一個很好的解決方案,但它可能需要大量工作,并且需要深入了解 BeautifulSoup 的工作原理,我懷疑你是否愿意這樣做.

                  Another trick is to write code that "prunes the tree", eliminating any upward links from the div before/as you pickle it. This is a great solution, except that it might be a lot of work, and requires diving into the internals of how BeautifulSoup works, which I doubt you want to do.

                  最簡單的解決方法有點笨拙,但是……您可以將湯轉換為字符串,將其傳遞給孩子,然后讓孩子重新解析它:

                  The easiest workaround is a bit clunky, but… you can convert the soup to a string, pass that to the child, and have the child re-parse it:

                  def new_check():
                      divTexts = [str(div) for div in divList]
                      with Pool() as pool:
                          pool.map(get_info, divTexts)
                  
                  def get_info(each):
                      div = BeautifulSoup(each, 'html.parser')
                  
                  if __name__ == '__main__':
                      new_check()
                  

                  這樣做的性能成本可能無關緊要;更大的擔憂是,如果您的 HTML 不完美,則轉換為字符串并重新解析它可能不是完美的往返.所以,我建議你先做一些沒有多處理的測試,以確保這不會影響結果.

                  The performance cost for doing this is probably not going to matter; the bigger worry is that if you had imperfect HTML, converting to a string and re-parsing it might not be a perfect round trip. So, I'd suggest that you do some tests without multiprocessing first to make sure this doesn't affect the results.

                  這篇關于超出最大遞歸深度.多處理和 bs4的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)

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

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

                          <legend id='oDapw'><style id='oDapw'><dir id='oDapw'><q id='oDapw'></q></dir></style></legend>
                            主站蜘蛛池模板: 亚洲欧美日韩精品久久亚洲区 | 在线播放国产一区二区三区 | av手机在线看 | 成人欧美一区二区三区色青冈 | 久久精品国产一区二区电影 | 东京久久| 免费看黄视频网站 | 欧美成人免费在线 | 亚洲a级 | 羞羞视频在线观看免费观看 | 日朝毛片 | 精品视频在线观看 | 欧美a区 | 日韩精品| 国产综合欧美 | 一级黄色毛片免费 | 伊人色综合久久天天五月婷 | 免费看一区二区三区 | 中文字幕第5页 | 18成人在线观看 | 欧美精品一区二区三区在线播放 | 午夜国产 | 婷婷丁香激情 | 国产亚洲一区二区在线观看 | 久久高清精品 | 91久久精品一区二区二区 | 欧美综合视频在线 | 国产精品av久久久久久久久久 | 亚洲精品电影网在线观看 | 中文字幕免费在线 | 一级aaaaaa毛片免费同男同女 | 手机av在线| 国产福利在线免费观看 | 日韩一区二区三区精品 | 国产午夜精品一区二区三区嫩草 | 日韩av电影在线观看 | 国产精品美女久久久久久免费 | 久久精品一区二区 | 国产在线麻豆精品入口 | 日本精品一区二区三区在线观看 | 九九综合九九 |