unpickling a stream

M

msolem

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
 
R

ryles

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top