Python 3.x Python3 Pickle达到递归极限

Python 3.x Python3 Pickle达到递归极限,python-3.x,serialization,pickle,Python 3.x,Serialization,Pickle,我有以下代码块,当在我的Ubuntu计算机上使用Python3执行时,会遇到递归错误以进行酸洗。我不明白为什么,因为要pickle的对象并不特别复杂,也不涉及任何自定义对象。事实上,它只是一个大约500个元素的列表(大约);列表中的每个元素都只是一个字符串。在我看来,我应该能够毫无问题地序列化这个对象。为什么我遇到了递归限制错误?我知道我可以通过import sys和sys.setrecursionlimit()来提高递归限制,但坦率地说,我很惊讶我必须为这样一个微不足道的对象这么做 from

我有以下代码块,当在我的Ubuntu计算机上使用Python3执行时,会遇到递归错误以进行酸洗。我不明白为什么,因为要pickle的对象并不特别复杂,也不涉及任何自定义对象。事实上,它只是一个大约500个元素的列表(大约);列表中的每个元素都只是一个字符串。在我看来,我应该能够毫无问题地序列化这个对象。为什么我遇到了递归限制错误?我知道我可以通过
import sys
sys.setrecursionlimit()
来提高递归限制,但坦率地说,我很惊讶我必须为这样一个微不足道的对象这么做

from urllib import request
from bs4 import BeautifulSoup
import pickle


def get_standard_and_poors_500_constituents():
    # URL request, URL opener, read content.
    req = request.Request(
        "http://en.wikipedia.org/wiki/List_of_S%26P_500_companies"
    )
    opener = request.urlopen(req)
    # Convert bytes to UTF-8.
    content = opener.read().decode()
    soup = BeautifulSoup(content, "lxml")
    # HTML table we actually need is the first.
    tables = soup.find_all("table")     
    external_class = tables[0].findAll("a", {"class":"external text"})
    c = [ext.string for ext in external_class if not "reports" in ext]

    return c


sp500_constituents = get_standard_and_poors_500_constituents()
spdr_etf = "SPY"
sp500_index = "^GSPC"


def main():
    import datetime as dt
    today = dt.datetime.today().date()
    fname = "sp500_constituents_" + str(today) + ".pkl"

    with open(fname, "wb") as f:
        pickle.dump(sp500_constituents, f)


if __name__ == "__main__":
    main()