Hendrik van Rooyen
mail at microcorp.co.za
Thu Oct 5 11:57:28 CEST 2006
"Fredrik Lundh" <fredrik at pythonware.com> wrote:
> Eric Brunel wrote:
> > AFAIK, Tkinter is not thread safe. Using some kind of lock to serialize
> > the calls from different threads may seem to work (I never tested it
> > actually), but the safest way I found to use threads with Tkinter was to
> > call it only from the thread where the main loop executes.
> the Tkinter binding contains some code that attempts to deal with re-
> entrant calls, but I don't know/remember to what extent it's actually
> supposed to work (in other words, if the observed problems are bugs or
> just limitations).
> (maybe Martin's memory is better?)
> anyway, I usually play it safe and make sure to use a single thread to
> deal with the UI.
I must be dense - After I have called mainloop, if I have not started another
thread to respond to events that are not generated by the user on the screen (in
this case values of variables to display from the field generated by different
processes - there is other hardware out there), how do I get control back to do
the necessary updating? - I suppose I can use the call back after some time
thingy to implement a polling loop - possibly as Russel Owen suggested - by
polling a queue - but queues are for between threads - and I have seen here
somewhere that sockets also want to be the main thread - so that leaves a
pipe - and I have had bad experiences with pipes that are unblocked, and if I
don't unblock it, then the gui will grind to a halt....so I need a thread for
the pipe between processes, and a queue between threads, and a time out based
polling loop to read the queue, it seems - is it even safe to change a main loop
variable from another thread? , or should I do it all via commands through a
queue, implementing a whole goddam serial protocol just between threads? and If
I don't have another thread to do the timing for the animation bits, then I must
base that on a timed callback too, and somehow keep state between callbacks...
now is it ok to call widget command methods from a callback in the same thread,
or do I have to use invoke?
My head is beginning to hurt... - what was a nice simple threaded implementation
is turning into a spaghetti monster of timed callbacks - you thought gotos was
bad? - you aint seen nothing yet...
More information about the Python-list