python - pickle.dump meet RuntimeError: maximum recursion depth exceeded in cmp -
i have noticed may caused beautifulsoup or recursive data structure. however, data structure cause error seems no problem:
class movie: def __init__(self, name="", dscore=0, mscore=0, durl="", murl=""): self.name = name self.dscore = float(dscore) self.mscore = float(mscore) self.durl = durl self.murl = murl def __str__(self): return unicode(self.name) + u' / ' + unicode(self.dscore) + u' / ' + unicode(self.mscore) \ + u' / ' + unicode(self.durl) + u' / ' + unicode(self.murl) the statement causing problem is:
datadict['movieinfo'] = movieinfo and
pickle.dump(datadict, f, true) following function:
def savedata(): global linkurlqueue global movieset global movieinfo global linkurlset global movieurlqueue datadict = {} datadict['linkurlset'] = linkurlset datadict['movieset'] = movieset #datadict['movieinfo'] = movieinfo datadict['linkurlqueue'] = linkurlqueue datadict['movieurlqueue'] = movieurlqueue f = open('movieinfo.txt', 'wb') item in movieinfo: f.write(item.__str__().encode('utf8') + '\n'.encode('utf8')) f.close() try: print 'saving data...' f = open('spider.dat', 'wb') pickle.dump(datadict, f, true) f.close() except ioerror e: print 'ioerror, error no: %d' % e.no print 'saved spider2.dat' pickle.dump(datadict, open('spider2.dat', 'wb')) time.sleep(10) my complete source code:
spider.py: http://paste.ubuntu.com/7149731/
fetch.py: http://paste.ubuntu.com/7149732/
you can download , run.
besides, welcome coding style suggestions
well... solve problem myself...
the reason problem pickle cannot handle beautifulsoup!!! generally, cannot handle html parser.
i realize when passing arguments functions, should convert them str() or unicode() assignments, instead of remaining them beautifulsoup objects...
thanks everyone~
Comments
Post a Comment