title: How to cancel a matplotlib callback event when new event enters event queue?
body: <p>In the code below if I hover over the figure it generates, it will print "not slept" <em>take a couple seconds to do computation</em> then print "slept" and repeat until the event queue empties. What I want to happen is that during the 2 second wait if it detects a new hover position instantly cancels the sleep event and run the new hover call. or if this is not possible remove all but the very last event call and the one that it is currently working on. </p>
  
  <pre><code>import matplotlib.pyplot as plt
  import time
  
  def hover(evnt):
      print('not slept')
      [i**i for i in range(10000)]
      print('slept')
  
  f = plt.figure()
  plt.plot([1,2,3],[1,2,3])
  f.canvas.callbacks.connect("motion_notify_event", hover)
  plt.show()
  </code></pre>