Orest Kozyar wrote: >> Please post the entire traceback (omitting duplicate lines). >> > > Sorry, I should have included the traceback. I've revised the sample script > so that it generates the traceback when run. The sample script is at the > very bottom of this email. >
It appears you have a cyclic reference in your doc object. Try adding "doc.unlink()" before you add it to your shelf. > ####### SCRIPT OUTPUT ####### > [kozyar]:~$ python example.py > > Successfully retrieved and parsed XML document with ID 16842423 > Successfully shelved XML document with ID 16842423 > Successfully retrieved and parsed XML document with ID 16842422 > > Traceback (most recent call last): > File "example.py", line 30, in <module> > data[badkey] = doc > File "/usr/lib64/python2.5/shelve.py", line 123, in __setitem__ > p.dump(value) > RuntimeError: maximum recursion depth exceeded > > Exception exceptions.RuntimeError: 'maximum recursion depth exceeded' in > <bound method DbfilenameShelf.__del__ of {'16842423': > <xml.dom.minidom.Document instance at 0x96f290>}> ignored > > > ####### START SCRIPT ####### > import urllib, shelve > from xml.dom import minidom > > baseurl = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?' > > params = { > 'db': 'pubmed', > 'retmode': 'xml', > 'rettype': 'medline' > } > > badkey = '16842422' > goodkey = '16842423' #or just about any other ID > > data = shelve.open('data.tmp', writeback=True) > > params['id'] = goodkey > url = baseurl + urllib.urlencode(params) > doc = minidom.parseString(urllib.urlopen(url).read()) > print 'Successfully retrieved and parsed XML document with ID %s' % goodkey > data[goodkey] = doc > print 'Successfully shelved XML document with ID %s' % goodkey > > params['id'] = badkey > url = baseurl + urllib.urlencode(params) > doc = minidom.parseString(urllib.urlopen(url).read()) > print 'Successfully retrieved and parsed XML document with ID %s' % badkey > data[badkey] = doc > #Will fail on the above line > print 'Successfully shelved XML document with ID %s' % badkey > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor