Invoke a method to a specific thread

Diez B.Roggisch deets at web.de
Mon Jul 25 07:03:08 EDT 2005


Varghjärta <varghjarta <at> gmail.com> writes:

> If I have "GUIClass":...
> And start another thread and from that thread I want to call the
> method "PaintSomething()" in "GUIClass" _in_ the same thread that
> "GUIClass" lives in.

There is no such thing in python, or any programming language for that matter. 
If a thread wants to run in an endless loop, there is nothing you can do about
that - apart from maybe killing it. But even that won 't work all the time and is
dangerous.

However, in GUIs there is usually some so called event-loop. And for the
task you have in mind you need a way to insert a custom event into that loop
that will be executed the next time that gui thread is idle. 
Qt uses QCustomEvents for this. Swing has it's SwingUtilities.invokeLater 

http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html#invokeLater

and others have different means. So - whatever GUI you use, 
it depends on that what to do.

Diez




More information about the Python-list mailing list