Re: Invoke a method to a specific thread

Discussion in 'Python' started by =?ISO-8859-1?Q?Varghj=E4rta?=, Aug 4, 2005.

  1. On 25/07/05, Diez B.Roggisch <> wrote:
    > Varghjärta <varghjarta <at>> 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.

    Not exactly sure what you mean, what would you call the ability to
    sort of, push a method call onto a thread like Invoke() in C# for
    Even if underneath the clean surface it posts the call into the
    message loop it gets the job done.

    > 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
    > and others have different means. So - whatever GUI you use,
    > it depends on that what to do.

    Yeah, I've been playing around with WX and find it to be the best GUI
    layer for python, I belive it has some way of dealing with it.

    But lets say i'm not using a GUI. Or rather, for example in my
    WxPython application I have classes which needs to perform time
    consuming operations. I would _really_ not want to include lots of
    WX-stuff in an otherwise purely python class. I don't like mixing GUI
    code with other code, it feels very dirty.

    How would a python programmer(more experienced then I currently am) solve this?

    Should I implement some kind of message-loop-system in the class which
    the different threads "posts" to, and then the class(which is in the
    right thread) deals with any events "posted"?

    I'm spoiled from C# having everything delivered to me, so I'm confused
    as to how much I need to implement myself. Thinking perhaps there was
    some cute special python command I could use to do it for me :)

    P.S. Currently traveling far from home(but still I have programming on
    me brain), sorry for the delayed reply.
    =?ISO-8859-1?Q?Varghj=E4rta?=, Aug 4, 2005
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jerry051
    Oliver Sturm
    Aug 2, 2005
  2. Henrik Dahl
    Henrik Dahl
    May 21, 2004
  3. Storm
    Chris Uppal
    May 1, 2004
  4. =?ISO-8859-1?Q?Varghj=E4rta?=

    Invoke a method to a specific thread

    =?ISO-8859-1?Q?Varghj=E4rta?=, Jul 25, 2005, in forum: Python
    Jul 25, 2005
  5. lyallex
    Sep 29, 2007

Share This Page