title: Python multithreading with shared variable
body: <p>I'm trying to parallelise my job, but I'm new to multithreading, so feel confused about the concrete implementation.</p>
  
  <p>I have a socket listener, that saves data to a buffer. When buffer reaches his capacity I need to save its data to database.
  On one thread I want to start socket listener, while on parallel task I want to check the buffer status.</p>
  
  <p><code>BufferQueue</code> is just an extension of a python <code>list</code>, with method that allow to check whether the list has reached the specified size.</p>
  
  <p><code>SocketManager</code> is streaming data provider of a <code>STREAM_URL</code> I'm listening to. It use callback function to handle messages</p>
  
  <p>But as I use callbacks to retrieve data I'm not sure that using shared variable is a right and optimal decision for that</p>
  
  <pre><code>buffer = BufferQueue(buffer_size=10000)
  
  def start_listening_to_sokcet(client):
      s = SocketManager(client)
      s.start_socket(cb_new)
      s.start()
  
  def cb_new(message):
      print("New message")
      global buffer
      for m in message:
          #save data to buffer
  
  def is_buffer_ready(buffer):
      global buffer
      print("Buffer state")
      if buffer.ready():
           #save buffer data to db
  </code></pre>
  
  <p>I'm appreciate if you can help me with this case</p>