[Python-Dev] Event loops, PyOS_InputHook, and Tkinter
edloper at gradient.cis.upenn.edu
Mon Nov 14 06:35:31 CET 2005
As I understand it, you want to improve the performance of interactively
run plot commands by queuing up all the plot sub-commands, and then
drawing them all at once. Hooking into a python event loop certainly
isn't the only way to do this. Perhaps you could consider the following
- The plot event loop is in a separate thread, accepting messages
from the interactive thread.
- These messages can contain plot commands; and they can also contain
two new commands:
- suspend -- stop plotting, and start saving commands in a queue.
- resume -- execute all commands in the queue (with whatever
increased efficiency tricks you're using)
Then you can either just add functions to generate these messages, and
call them at appropriate places; or set PyOS_InputHook to wrap each
interactive call with a suspend/resume pair.
But note that putting an event loop in a separate thread will be
problematic if you want any of the events to generate callbacks into
user code -- this could cause all sorts of nasty race-conditions! Using
a separate thread for an event loop only seems practical to me if the
event loop will never call back into user code (or if you're willing to
put the burden on your users of making sure everything is thread safe).
More information about the Python-Dev