title: Python unpickling stack underflow
body: <p>I've been working on a python application, where the client sends a clock signal to the server and the server responds with an audio signal.<br>
  I have two buttons, one to start the clock and one to pause the track.<br></p>
  
  <p><strong>Main Class</strong></p>
  
  <pre><code># function I call when I hit the play button
  def play(self):
      start_song = [250]
      global IS_FIRST_PLAY
      if IS_FIRST_PLAY:
          IS_FIRST_PLAY = False
          self.startClock()
      if IS_CONNECTED:
          client.sendMessage(start_song)
  
  # here I start the clock and send a constant clock signal to the client
  def startClock(self):
      clock = midi.startClock()
      for i in clock:
          if IS_CONNECTED:
              client.sendMessage(i)
      midi.playing = True
  
  # here I pause the track
  def pause(self):
      stop_song = [252]
      if IS_CONNECTED:
          client.sendMessage(stop_song)
      midi.sendMidiMessage(stop_song)
      midi.playing = False
      midi.mtClock = [0, 0, 0, 0]
  </code></pre>
  
  <p><strong>Client class</strong></p>
  
  <pre><code># this is the client.sendMessage() function
  def sendMessage(self, message):
      self.s.sendall(pickle.dumps(message))
  </code></pre>
  
  <p><strong>Server class</strong></p>
  
  <pre><code># this is the class that handles the incoming clock signal for the server
  class MyTCPHandler(socketserver.BaseRequestHandler):
  
      def handle(self):
          global IS_FIRST_PLAY, IS_PLAYING      
          thread1 = threading.Thread(target=self.sendAudio)
          thread1.start()
          while True:
              # here throws python an error
              self.data = pickle.loads(self.request.recv(12).strip())
  </code></pre>
  
  <p>This all works fine, except for a random moment, when I change pause to play, I keep getting this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/socketserver.py", line 306, in _handle_request_noblock
      self.process_request(request, client_address)
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/socketserver.py", line 332, in process_request
      self.finish_request(request, client_address)
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/socketserver.py", line 345, in finish_request
      self.RequestHandlerClass(request, client_address, self)
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/socketserver.py", line 666, in __init__
      self.handle()
    File "/Users/cedricgeerinckx/Dropbox/Redux/OSX/Server.py", line 85, in handle
      self.data = pickle.loads(self.request.recv(12).strip())
  _pickle.UnpicklingError: unpickling stack underflow
  </code></pre>
  
  <p>What can this issue possibly be?</p>