title: How can a client handle data that comes from a stream faster than it can be processed? - Python
body: <p>I am trying to stream market data from my broker and all the examples I've seen handle one item at a time. However, what happens if it takes 200ms to process an item but the stream is delivering items every 50ms? The market data would increasingly become out of sync and irrelevant, correct? I imagine this is a common problem for many applications and I'm amazed I couldn't find anything on this topic with my searches. How do people deal with this in Python? Threading? Also, I don't understand why all the examples I've seen don't have a process in place to handle this possibility; do people just assume they can process faster than the data stream and therefore only process one item at a time?</p>
  
  <p>I just want to ensure my script will be using the latest market data as that's critical when making trades. I'm quite inexperienced with streaming, WebSockets, asyncio, threading, so whatever information you can provide would be greatly appreciated. Thank you for your time.</p>
  
  <p>If necessary, my current code in its basic form is as follows:</p>
  
  <pre><code>async with websockets.connect(uri) as websocket:
      await websocket.send(payload)
  
      while True:
          response = await websocket.recv()
  
          # Process response
  </code></pre>