Python pickle._dumps works while pickle.dumps fails

Viewed 86

I ran into an issue recently where I tried to do Pickle (Python 3.6) on an object of type: twilio.rest.chat.v2.service.channel.ChannelInstance (The code for it can be found here. )

The relevant code was just this:

picked_rv = pickle.dumps(value)

it would result in: TypeError: can’t pickle _thread.RLock objects on our server or AttributeError: Can't pickle local object 'init_logging.<locals>.NotProductionHandler' on my local system. Both RLock and NotProductionHandler are objects in the same environment as the ChannelInstance but not actually referenced by it at all, i.e. those are objects I instantiated in the same context while making a call to Twilio and getting the ChannelInstance back.

However, as soon as I try to use the pure Python Pickle instead of the cPickle (or _pickle in the module) dumps like this:

picked_rv = pickle._dumps(value)

it would work just fine. Can anyone explain the difference in behavior? I'm just baffled by both the error and difference in behavior. Why would cPickle try to pull in the other variables and objects in the context and then why would the pure Python implementation work?

This was not an issue with on Twilio 6.18.0, cPickle worked just fine, but I suspect the issue is Pickle.

Thanks in advance.

0 Answers
Related