question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incompatible with pickle library

See original GitHub issue

Pickle library won’t support the mock datetime objects:

In [1]: from freezegun import freeze_time

In [2]: import datetime

In [3]: import pickle

In [4]: import StringIO

In [5]: freezer = freeze_time("2012-12-12")

In [6]: freezer.start()

In [7]: f=StringIO.StringIO()

In [8]: pickle.dump(datetime.datetime.now(), f)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (156, 0))

---------------------------------------------------------------------------
PicklingError                             Traceback (most recent call last)

/vagrant/<ipython console> in <module>()

/usr/lib/python2.7/pickle.pyc in dump(obj, file, protocol)
   1368 
   1369 def dump(obj, file, protocol=None):
-> 1370     Pickler(file, protocol).dump(obj)
   1371 
   1372 def dumps(obj, protocol=None):

/usr/lib/python2.7/pickle.pyc in dump(self, obj)
    222         if self.proto >= 2:
    223             self.write(PROTO + chr(self.proto))
--> 224         self.save(obj)
    225         self.write(STOP)
    226 

/usr/lib/python2.7/pickle.pyc in save(self, obj)
    329 
    330         # Save the reduce() output and finally memoize the object

--> 331         self.save_reduce(obj=obj, *rv)
    332 
    333     def persistent_id(self, obj):

/usr/lib/python2.7/pickle.pyc in save_reduce(self, func, args, state, listitems, dictitems, obj)
    398             write(NEWOBJ)
    399         else:
--> 400             save(func)
    401             save(args)
    402             write(REDUCE)

/usr/lib/python2.7/pickle.pyc in save(self, obj)
    284         f = self.dispatch.get(t)
    285         if f:
--> 286             f(self, obj) # Call unbound method with explicit self
    287             return
    288 

/usr/lib/python2.7/pickle.pyc in save_global(self, obj, name, pack)
    751                 raise PicklingError(
    752                     "Can't pickle %r: it's not the same object as %s.%s" %
--> 753                     (obj, module, name))
    754 
    755         if self.proto >= 2:

PicklingError: Can't pickle <type 'datetime.datetime'>: it's not the same object as datetime.datetime

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nickwilliams-eventbritecommented, Apr 19, 2018

I’m sorry for resurfacing this very old issue. Please ignore my stupidity. After extensive debugging, I discovered that an instance of the _freeze_time class was making its way into the dict I was trying to copy. Resolving that fixed my problem. Nothing to see here. Move along.

0reactions
nickwilliams-eventbritecommented, Apr 19, 2018

Has this regressed in 0.3.x? I’m getting TypeError: can't pickle NotImplementedType objects when trying to copy.deepcopy any object with a faked date/time/datetime in it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pickle — Python object serialization
The pickle module implements binary protocols for serializing and de-serializing a Python object structure. “Pickling” is the process whereby a Python ...
Read more >
Unable to load files using pickle and multiple modules
The issue is that you're pickling objects defined in Settings by actually running the 'Settings' module, then you're trying to unpickle the ...
Read more >
Pickle's nine flaws | Ned Batchelder
Python's pickle module is a very convenient way to serialize and de-serialize objects. But it has nine problems.
Read more >
The Python pickle Module: How to Persist Objects in Python
The Python pickle module is another way to serialize and deserialize objects in Python. It differs from the json module in that it...
Read more >
28444 (Fix backwards incompatibility of unpickling in Python 3)
So, the Python-3 pickle can be unpickled in Python-2, but not the other way ... unpickling aborts before a call to code from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found