BS4 MemoryError: stack overflow and EOFError: Ran out of input when using multiprocessing in python

I have a simple python script that utilizes Python's BS4 library and multiprocessing to do some web scraping. I was initially getting some errors where the script would not complete since I would exceed the recursion limit, but then I found out here that BeautifulSoup trees cannot be pickled, and so causes issues with multiprocessing, so I followed one recommendation in the top answer which was to do the following: sys.setrecursionlimit(25000)

This worked fine for a couple of weeks with no issues (as far as I could tell), but today I restarted the script and some of the processes do not work and I get the error that you can see below:

I now get this error:

Traceback (most recent call last):
  File "C:/Users/user/PycharmProjects/foo/single_items/", line 243, in <module>
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\multiprocessing\", line 112, in start
    self._popen = self._Popen(self)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\multiprocessing\", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\multiprocessing\", line 322, in _Popen
    return Popen(process_obj)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\multiprocessing\", line 89, in __init__
    reduction.dump(process_obj, to_child)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\multiprocessing\", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\bs4\", line 1449, in __getattr__
    "'%s' object has no attribute '%s'" % (self.__class__, tag))
MemoryError: stack overflow
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\multiprocessing\", line 105, in spawn_main
    exitcode = _main(fd)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\multiprocessing\", line 115, in _main
    self = reduction.pickle.load(from_parent)
EOFError: Ran out of input

I am not sure what it means, but here is a pseudocode example of the script I have running:

class foo:
    def __init__(url):
        self.url = url

    def constant_scrape:
        while True:
            rq = make_request(url)
            soup = BeautifulSoup(rq)

if __name__ == '__main__':


    url_list = [...]

    for url in url_list:
        instance = foo(url)

Read more here:

Content Attribution

This content was originally published by user13834264 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: