title: Python - Skipping websocket callback "queue"
body: <p>I have the following:</p>
  
  <pre><code>def process(msg):
      print(msg)
  
      for i in range(10):         # This is in place of the
          print(i, end=' ')       # actual task, which takes
          time.sleep(1)           # around 10 seconds to run
  
  ws = websocket()
  ws.start_socket_abc(callback=process)
  </code></pre>
  
  <p>The websocket pushes info every second and makes a call to <code>process</code> each time.</p>
  
  <p>Say the websocket is returning <code>"one"</code> for this second, <code>"two"</code> for the next second, <code>"three"</code> for the second after, and so on. Running the above code, the ouput would be:</p>
  
  <pre><code>one
  0 1 2 3 4 5 6 7 8 9   &lt;- this line takes 10 seconds to finish
  two
  0 1 2 3 4 5 6 7 8 9   &lt;- this line takes 10 seconds to finish
  ...
  </code></pre>
  
  <p>It's clear that <code>process("two")</code> gets queued somewhere and is waited to be called after <code>process("one")</code> finishes. By the time the program prints out <code>two</code>, the real-time message should be <code>twelve</code>.</p>
  
  <p>What I'm trying to achieve is to completely skip the "queue". I want it to take the message, do the task, skip all the calls in between (this is important, I actually need to skip them), take the next real-time message and do the task. In short, I want it to print out whatever real-time message is at the moment <code>process("one")</code> finishes. i.e.</p>
  
  <pre><code>one
  0 1 2 3 4 5 6 7 8 9   &lt;- this line takes 10 seconds to finish
  twelve
  ...
  </code></pre>
  
  <p>This is what I have in mind.</p>
  
  <pre><code>message = ''
  def process(msg):
      message = msg
  
  ws = websocket()
  ws.start_socket_abc(callback=process)
  
  def task(msg=message):
      print(msg)
  
      for i in range(10):         # This is in place of the
          print(i, end=' ')       # actual task, which takes
          time.sleep(1)           # around 10 seconds to run
  
  start_thread(target=task)
  </code></pre>
  
  <p>This performs the task with the <code>message</code> variable, which changes in real-time with the messages received from the websocket so after <code>task("one")</code> finishes, <code>message</code> is at <code>"twelve"</code> and <code>task("twelve")</code> will be called, skipping all the messages in between.</p>
  
  <p>I strongly doubt that this is the proper way of doing it. Someone please enlighten me, thanks in advance!</p>