3

When comparing ujson and cpickle for serializing objects in Python 2.7, why does using ujson as shown gives an error OverflowError: Maximum recursion level reached?

import ujson as json
sys.setrecursionlimit(10000)
with open(myPath, 'w') as fp:
    json.dump(data, fp)

However when using cPickle, the same error does not occur.

import cPickle as pickle
sys.setrecursionlimit(10000)
with open(myPath, 'w') as fp:
    pickle.dump(data, fp)

Why is this?

Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
  • hmm my data works fine with either ... but at a guess I would say codes ... actually i take that back ive never tried ujson ... simplejson is very fast though – Joran Beasley Oct 03 '15 at 06:32
  • You may have found a bug. Report it on the python dev site along with your data file. – sureshvv Oct 03 '15 at 07:01
  • The recursive depth of the traversal of data is not necessarily the same in ujson and cPickle and so they won't necessarily fail on the same data. On the other hand there might be a bug in ujson's handling of recursive structures. Does your data have reference loops? You need to explore how the two packages react to different, simpler, data items. Try a simple list that contains itself. – strubbly Oct 03 '15 at 07:24

0 Answers0