MemoryError while pickling data in python

2024/10/5 7:24:44

I am trying to dump a dictionary into pickle format, using 'dump' command provided in python. The file size of the dictionary is around 150 mb, but an exception occurs when only 115 mb of the file is dumped. The exception is:

Traceback (most recent call last): File "C:\Python27\generate_traffic_pattern.py", line 32, in <module> b.dump_data(way_id_data,'way_id_data.pickle') File "C:\Python27\class_dump_load_data.py", line 8, in dump_data pickle.dump(data,saved_file) File "C:\Python27\lib\pickle.py", line 1370, in dump Pickler(file, protocol).dump(obj) File "C:\Python27\lib\pickle.py", line 224, in dump self.save(obj) File "C:\Python27\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "C:\Python27\lib\pickle.py", line 649, in save_dict self._batch_setitems(obj.iteritems()) File "C:\Python27\lib\pickle.py", line 663, in _batch_setitems save(v) File "C:\Python27\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "C:\Python27\lib\pickle.py", line 600, in save_list self._batch_appends(iter(obj)) File "C:\Python27\lib\pickle.py", line 615, in _batch_appends save(x) File "C:\Python27\lib\pickle.py", line 286, in save f(self, obj) # Call unbound method with explicit self File "C:\Python27\lib\pickle.py", line 599, in save_list self.memoize(obj) File "C:\Python27\lib\pickle.py", line 247, in memoize self.memo[id(obj)] = memo_len, obj 
MemoryError

I am really confused, since my same code was working fine earlier.

Answer

Are you dumping just that one object, and that's all?

If you are calling dump many times, then calling Pickler.clear_memo() between dumps will flush the internally stored backreferences (causing the 'leak'). And your code should just work fine...

https://en.xdnf.cn/q/70508.html

Related Q&A

numpy dimensions

Im a newbie to Numpy and trying to understand the basic question of what is dimension,I tried the following commands and trying to understand why the ndim for last 2 arrays are same?>>> a= ar…

DataFrame Plot: how to sort X axis

I am plotting some counts from a field of dataframe (pandas) and I found that the X axis is sorted by the counts (descending order). Instead is it possible to sort by the alphabetical order of the fiel…

In-place custom object unpacking different behavior with __getitem__ python 3.5 vs python 3.6

a follow-up question on this question: i ran the code below on python 3.5 and python 3.6 - with very different results:class Container:KEYS = (a, b, c)def __init__(self, a=None, b=None, c=None):self.a …

Different ways of using __init__ for PyQt4

So... Im working on trying to move from basic Python to some GUI programming, using PyQt4. Im looking at a couple different books and tutorials, and they each seem to have a slightly different way of k…

Numpy: Reshape array along a specified axis

I have the following array:x = np.arange(24).reshape((2,3,2,2)) array([[[[ 0, 1],[ 2, 3]],[[ 4, 5],[ 6, 7]],[[ 8, 9],[10, 11]]],[[[12, 13],[14, 15]],[[16, 17],[18, 19]],[[20, 21],[22, 23]]]])I wou…

python suds wrong namespace prefix in SOAP request

I use python/suds to implement a client and I get wrong namespace prefixes in the sent SOAP header for a spefic type of parameters defined by element ref= in the wsdl. The .wsdl is referencing a data …

Allow help() to work on partial function object

Im trying to make sure running help() at the Python 2.7 REPL displays the __doc__ for a function that was wrapped with functools.partial. Currently running help() on a functools.partial function displ…

How To Fix Miscased Procfile in Heroku

Heroku will not reload my corrected ProcfileI have ran git status which shows me the Procfile and I realized that I spelled Procfile with a lower case p. I saw the error and updated the file name in my…

Using Pythons xml.etree to find element start and end character offsets

I have XML data that looks like:<xml> The captial of <place pid="1">South Africa</place> is <place>Pretoria</place>. </xml>I would like to be able to extra…

How to get public key using PyOpenSSL?

Im tring to create python script, that would take PKCS#12 package and print some information contained in x509 certificate and using for this purpouses PyOpenSSL module. So far i want to fetch from cer…