On May 26, 3:25 pm, mso...@linuxmail.org wrote: > Hello, > > I want to send a stream of pickled objects over a socket. Is there a > standard way of ensuring that only complete objects are unpickled on > the receiving side. > > client pseudo code: > loop forever: > receive some bytes on the socket > if we have received a complete pickled object: <== How is this > done? > unpickle the object > > This isn't for a project, just trying to learn some more about the > pickle module. > > Mike
If you'd like, you can turn a socket into a file-like object using its makefile() method. An Unpickler will know when to stop reading from the file (there's a STOP character in the pickle format). David Beazley gives an example of this approach in Part 7 of "Generator Tricks for Systems Programmers": http://www.dabeaz.com/generators/Generators.pdf -- http://mail.python.org/mailman/listinfo/python-list