title: _pickle.UnpicklingError: could not find MARK
body: <p>I got exceptions like <strong>UnicodeDecodeError</strong> raised when pickling (a list of) objects of EventFrame with a member <em>participants</em> that was an empty set.</p>
  
  <pre><code>class EventFrame:
      """Frame for an event"""
      def __init__(self, id=0):
          ...
          self.participants = set()
          ...
  </code></pre>
  
  <p>When it wasn't empty, there were no problems, so I first set <em>participants</em> to something and then pickled it. But during runtime it may happen that <em>participants</em> is emptied again.</p>
  
  <p>So I tried to manually delete the object in this case. After that I dumped it again using pickle.</p>
  
  <pre><code>if len(frame.participants) == 0:
      frame_list.remove(frame)
  </code></pre>
  
  <p>That doesn't seem to be a good choice, because this <strong>UnpicklingError</strong> was raised:</p>
  
  <pre><code>....
  frame_list.append (pickle.load(f))
  _pickle.UnpicklingError: could not find MARK
  </code></pre>
  
  <p>I don't know what it means and I couldn't find anything useful about it.</p>
  
  <p><strong>Note</strong> that this error is raised on loading the pickle file.</p>
  
  <p>Here is the way I'm picklng and unpickling:</p>
  
  <pre><code>f = open("myfile", "r+b")
  frame_list = []
  while 1:
      try:
          frame_list.append (pickle.load(f))
          frame_list = sum(frame_list, [])
      except EOFError:
          break
  f.close()
  </code></pre>
  
  <p>and dumping:</p>
  
  <pre><code>f = open("myfile", "r+b")
  pickle.dump(frame_list, f)
  f.close()   
  </code></pre>