Trying to render a large and (possibly very) unpicklable object to a file for later use.
No complaints on the dill.dump(file)
side:
In [1]: import echonest.remix.audio as audio
In [2]: import dill
In [3]: audiofile = audio.LocalAudioFile("/Users/path/Track01.mp3")
en-ffmpeg -i "/Users/path/audio/Track01.mp3" -y -ac 2 -ar 44100 "/var/folders/X2/X2KGhecyG0aQhzRDohJqtU+++TI/-Tmp-/tmpWbonbH.wav"
Computed MD5 of file is b3820c166a014b7fb8abe15f42bbf26e
Probing for existing analysis
In [4]: with open('audio_object_dill.pkl', 'wb') as f:
...: dill.dump(audiofile, f)
...:
In [5]:
But trying to load the .pkl
file:
In [1]: import dill
In [2]: with open('audio_object_dill.pkl', 'rb') as f:
...: audio_object = dill.load(f)
...:
Returns following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-203b696a7d73> in <module>()
1 with open('audio_object_dill.pkl', 'rb') as f:
----> 2 audio_object = dill.load(f)
3
/Users/mikekilmer/Envs/GLITCH/lib/python2.7/site-packages/dill-0.2.2.dev-py2.7.egg/dill/dill.pyc in load(file)
185 pik = Unpickler(file)
186 pik._main_module = _main_module
--> 187 obj = pik.load()
188 if type(obj).__module__ == _main_module.__name__: # point obj class to main
189 try: obj.__class__ == getattr(pik._main_module, type(obj).__name__)
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in load(self)
856 while 1:
857 key = read(1)
--> 858 dispatch[key](self)
859 except _Stop, stopinst:
860 return stopinst.value
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in load_newobj(self)
1081 args = self.stack.pop()
1082 cls = self.stack[-1]
-> 1083 obj = cls.__new__(cls, *args)
1084 self.stack[-1] = obj
1085 dispatch[NEWOBJ] = load_newobj
TypeError: __new__() takes at least 2 arguments (1 given)
The AudioObject is much more complex (and large) than the class object
the above calls are made on (from SO answer), and I'm unclear as to whether I need to send a second argument via dill
, and if so, what that argument would be or how to tell if any approach to pickling is viable for this specific object.
Examining the object itself a bit:
In [4]: for k, v in vars(audiofile).items():
...: print k, v
...:
returns:
is_local False
defer False
numChannels 2
verbose True
endindex 13627008
analysis <echonest.remix.audio.AudioAnalysis object at 0x103c61bd0>
filename /Users/mikekilmer/Envs/GLITCH/glitcher/audio/Track01.mp3
convertedfile /var/folders/X2/X2KGhecyG0aQhzRDohJqtU+++TI/-Tmp-/tmp9ADD_Z.wav
sampleRate 44100
data [[0 0]
[0 0]
[0 0]
...,
[0 0]
[0 0]
[0 0]]
And audiofile.analysis
seems to contain an attribute called audiofile.analysis.source
which contains (or apparently points back to) audiofile.analysis.source.analysis
cls.__new__(cls, *args)
– Maltechonest
API something I could grab a hold of to try out if needed? Anyway, there are a few things that you can try to discover what's going on. First, since it's a class, you can try to toggle thebyref
indill.dumps
, to toggle pickling the class "by reference". If that doesn't work, try turning ondill.detect.trace(True)
to see internal checkpoints in the (de)serialization. You can also look at methods indill.detect
, such asbadobjects
that can help diagnose what going on. It looks like a mismatch in__getstate__
and__setstate__
, which would be weird. – Tugboatwith open('audio_object_dill.pkl', 'wb') as f:
byref would be set like this,dill.dump(audiofile, f, byref=True)
withFalse
being the default, right?dill.load
results are the same. Entereddill.detect.trace(True)
prior todill.dump
call results: pastebin.com/V0fA7aVJ. Lastly,dill.detect.badobjects(audiofile)
returns<echonest.remix.audio.LocalAudioFile at 0x103ebc710>
. Hmph. – Maltdill.detect.children(audiofile, echonest.remix.audio.LocalAudioFile)
yields name 'echonest' is not defined - actually simply had to call it with the variable module was imported with:dill.detect.children(audiofile, audio.LocalAudioFile)
, which yields our old friend[<echonest.remix.audio.LocalAudioFile at 0x103ebc710>]
– Malttrace
you have in the pastebin. Yes, that's all the reading material ondill
, unfortunately. By the way, you should trybadobjects(audiofile, depth=1)
-- that allows you to dig into each object, even ones that fail. Also check out this as an example of what dill detection can do. #10082741 #25241639 – Tugboatf(self, obj) # Call unbound method with explicit self
in pickle'ssave
method. – Maltdump
, directly), and that might be why it seems likeload
expects something different. – Tugboat