[Tutor] in a pickle about pickle
nathan tech
nathan-tech at hotmail.com
Thu Aug 13 08:29:43 EDT 2020
Hi there,
I asked this question on stackoverflow, but realised I'd probably get
better answers here and should have have asked here in the first place
as the questions are a little bit newbieish.
I've done a lot of work with pickle, though only recently come across
cPickle which is faster (aparrently).
I was wondering though if someone would be able to answer these
questions for me though:
1. does pickle.dump(obj, file, protocol) thread itself in any way?
2. When I do something like: pickle.dump(obj, file, 2) the file that is
put out is still, mostly, human readable. Is this normal? It talks about
bytes in the docs which I took to mean it would not be human readable.
Related to this I also wanted to ask is there a way to see what function
is hanging a python process?
Allow me to explain this further as the obvious answers may not apply:
I have a program which has a graphical user interface through wx python.
As part of this program it saves data to files using pickle, because
they're dictionaries. I could use xml2dict and dict2xml, but cPickle is
faster (I think).
It executes the saving when you click a button. This occurs, the python
program freezes for a second, then goes bacck to the GUI. that's fine,
expected behaviour.
If I then click exit it returns to the console (expected), and then
sometimes will just sit there for about 10 to 15 minutes before finally
finishing.
I went into task manager and killed the task once, and found that the
data files were only half written, which is what leads me to believe it
is pickle that is either locking up or taking forever.
Annoyingly, since I played around with msgpack, json and then back to
cPickle it's not been doing it since, but I have observed this behaviour
with another one of my programs too.
Is this an issue that comes up often with pickle?
I work mostly with python dictionaries when dumping to files, which is
why I figured pickle would be the best option.
Thanks a lot for any help
Nathan
More information about the Tutor
mailing list