Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6364083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:07:09+00:00 2026-05-25T00:07:09+00:00

Note: This is closely related to my other topic here and here , but

  • 0

Note: This is closely related to my other topic here and here, but is an independent question and you needn’t read them if you’re not interested to..

I have some unexpected delays in processing items from the queue. It seems to be related to the matplotlib GUI thread, because I can make the delay arbitrarily long by avoiding generating any GUI events, but for example if I create some mouse move events, I can get at the queue. What is the cause of this delay and how to fix it?

# ~/repo/wim/mpl_q.py
import threading, Queue, time, random, sys

t0 = time.time()
t = lambda : time.time() - t0

def worker():
  while True:
    thing = queue.get()
    sys.stdout.write('({0}) hello {1}!\n'.format(t(), thing))
    queue.task_done()

queue = Queue.Queue()
thread = threading.Thread(target=worker)
thread.daemon = True
thread.start()

def say_hello(thing='world'):
  print '({0}) --> say_hello({1})'.format(t(), thing)
  queue.put(thing)

say_hello('world')
say_hello('cruel world')
say_hello('stack overflow')

import matplotlib.pyplot as plt
fig = plt.figure()

def event_handler(event):
  world = random.choice(['foo', 'bar', 'baz'])
  say_hello(world)

event_handler_ = lambda x: event_handler(x)
cid0 = fig.canvas.mpl_connect('key_press_event', event_handler)
cid1 = fig.canvas.mpl_connect('button_press_event', event_handler_)

plt.show()

Example of typical output , you can see the scripted items happen on time, but the user generated ones can come much later..

wim@wim-acer:~/repo/wim$ python mpl_q.py
(0.000166893005371) --> say_hello(world)
(0.000200986862183) --> say_hello(cruel world)
(0.000216960906982) hello world!
(0.000231027603149) --> say_hello(stack overflow)
(0.000247955322266) hello cruel world!
(0.00425505638123) hello stack overflow!
(7.80911588669) --> say_hello(foo)
(7.84842705727) hello foo!
(9.41998004913) --> say_hello(baz)
(11.4023530483) hello baz!
(14.3315930367) --> say_hello(foo)
(19.4317750931) hello foo!
(20.96124506) --> say_hello(bar)
(23.2277729511) --> say_hello(baz)
(23.2278220654) hello bar!
(29.0094120502) hello baz!

edit: I am using GTKAgg backend, and matplotlib version 1.1.0

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:07:10+00:00Added an answer on May 25, 2026 at 12:07 am

    I don’t really know why, but the problem seems to go away if you declare matplotlib.use(backend) before importing pyplot:

    import matplotlib
    matplotlib.use('TkAgg')
    import matplotlib.pyplot as plt
    

    In an interactive session, the problem can also be avoided by turning on interactive mode:

    import matplotlib.pyplot as plt
    plt.ion()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is closely related to, but is not the same question as: Java -
Note: This might seem like a Super User question at first, but please read
[Note: This question is very similar, but not quite the same.] I'm trying to
Note This is not a REBOL-specific question. You can answer it in any language.
(NOTE: This question is not about escaping queries, it's about escaping results) I'm using
This is pretty closely related to another SO question. Using the example below, could
NOTE: This question is only loosely related to tinyxml, however including details like that
NOTE: This question is related to CodeIgniter-RestServer When I call model.save() from backbone the
Note: This question uses jQuery but the question has nothing to do with jQuery
note: this question is related to PostGIS and Postgresql and is implemented with PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.