title: Can I define a queue Object "globally" to use it in a subfunction for a dynamic plot (Python)?
body: <p>I  write some sensorframes (each frame is an array with values) in a queue. This queue should be defined globally, so that it keep the frames if it is used in a subfunction. This subfunction deletes some frames in the queue using the get() command and fill it with new frames using the put() command, after this replenishment there is an evaluation (using the fft operation), this new result updates the plot (subfunction returns line,). To display the results I use the FuncAnimation() command (it repeats calling this subfunction to provide a dynamic plot). To provide this, it is therefore important to keep the frames in the queue, so that they will not be deleted when the FuncAnimation- Function calls it again. </p>
  
  <p>My question is how can I save the queue(with the preloaded sensorframes), so that I can call it in this subfunction? </p>
  
  <p>Or is this hole structure not suitable to solve this kind of task ? Maybe Singleton Concept or another OOP technique?  </p>
  
  <pre><code>#.....
  #.....
  def main():
  #........
  #......
  def read(n_frames=1):
      """Gets frame data from module"""
      data = []
      for i in range(n_frames):
          # reads sensorframes
          #...
      return data
  
  def datagen(i):  # def datagen(frames) ???
  
        framecount = 0
        getcount = 0
        fillcount= 0
  
        frames  = Queue()  # ?????
        while getcount &lt; 10:
  
            frames.get()
            getcount +=1
  
        while fillcount &lt; 10:
  
            #read frames from sensor 
            #....
            #...
            frames.put(frame)
            fillcount += 1
  
            l = list(frames.queue)   
            rd_history = np.array(l) 
  
            if fillcount &gt;= 10:     
               #.....
               #.....
  
                line.set_ydata(fft)
                return line,
  
  history = 100 
  frames = Queue() # ??? definition of this queue
  
  rd_history = read(history)  # this is for initialising the FuncAnimation
  #......
  #......
  fig, ax = plt.subplots()
  #...
  line, = ax.plot(fft)
  #....
  ani = FuncAnimation(fig, datagen,frames=1, blit=True, interval=2000) # repeats calling datagen 
  #......
  #.......
  plt.show()
  </code></pre>