1
Feb 09 '11
This might be surprising at first, but not really surprising if you think about it. While the objects are being deserialized, the unpickler constantly grabs stuff all around, modules, classes, functions, when relinking the instances to their classes and everything that wasn't pickled. If I'm not mistaken, it can actually import necessary modules as well.
So it might seem surprising if you're unpickling a huge list of integers, which could be done in background, sure, but which is not exactly the most common use case of pickle/cpickle.
1
u/heikkitoivonen Feb 10 '11
I don't think that has anything to do with it. cPickle dump and load get around the issue by freeing the GIL for some of the work that they do. dumps and loads could periodically release the GIL, too. Just releasing and immediately reacquiring after something like 1000 pickled objects would let other threads run reasonably well. I actually implemented something like this until I realized that dump and load already release the GIL.
1
-8
u/ipeev Feb 09 '11
There is nothing to beware about. Nobody is writing multithreaded applications in Python.
2
u/[deleted] Feb 09 '11
Man. There's a lot more reasons to beware of
pickleandcPicklethan that. This is pretty trivial.