Development

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Why not event-driven packages in other than the main thread?

    9 answers - 425 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hi,
    I've developed an application were I've used Tkinter for the GUI.
    When I ran the GUI in another thread than the main, it kept locking
    up.
    I experienced similar problems with Twisted.
    Both of these tools are event-based, so I guess that is the root of the
    problem
    But could anyone tell me why running these in a thread other than the
    main one doesn't work?
    regards
  • No.1 | | 353 bytes | |

    Tor Erik wrote:

    But could anyone tell me why running these in a thread other than
    the main one doesn't work?

    Just for personal interest: Why would you want to run the GUI in
    another thread? It's common to leave the GUI in the main thread and
    let worker threads handle heavy time-consuming stuff.

    Regards,

    B
  • No.2 | | 620 bytes | |

    Thu, 2006-09-14 at 11:13 +0200, Tor Erik wrote:
    Hi,

    I've developed an application were I've used Tkinter for the GUI.
    When I ran the GUI in another thread than the main, it kept locking
    up.
    I experienced similar problems with Twisted.

    Both of these tools are event-based, so I guess that is the root of the
    problem

    But could anyone tell me why running these in a thread other than the
    main one doesn't work?

    They probably use signals (Twisted I'm sure does) and it's documented
    that signals don't work with threads:

    Regards,
    Cliff
  • No.3 | | 259 bytes | |

    Thu, 2006-09-14 at 03:22 -0700, Cliff Wells wrote:
    They probably use signals (Twisted I'm sure does) and it's documented
    that signals don't work with threads:
    Er, specifically, they only work with the main thread.
    Cliff
  • No.4 | | 726 bytes | |

    Tor Erik <torerik81 (AT) gmail (DOT) comwrote:
    I've developed an application were I've used Tkinter for the GUI.
    When I ran the GUI in another thread than the main, it kept locking
    up.

    That's because Tkinter is not thread safe AFAIK.

    I experienced similar problems with Twisted.

    Neither Twisted is thread-aware. It uses thread for a couple of things
    (twisted.row and address resolution). You can call stuff in a separate
    thread with deferToThread or callInThread but avoid threads is best.

    But could anyone tell me why running these in a thread other than the
    main one doesn't work?

    Because neither Twisted nor Tkinter are meant to work with threads.
  • No.5 | | 555 bytes | |

    Bjoern Schliessmann wrote:
    Tor Erik wrote:

    >But could anyone tell me why running these in a thread other than
    >the main one doesn't work?


    Just for personal interest: Why would you want to run the GUI in
    another thread? It's common to leave the GUI in the main thread and
    let worker threads handle heavy time-consuming stuff.

    Regards,

    B

    If you have two event-based frameworks, both needing to run in the main
    thread, such as Tkinter and Twisted, you have a problem
  • No.6 | | 321 bytes | |

    Tor Erik <torerik81 (AT) gmail (DOT) comwrote:
    If you have two event-based frameworks, both needing to run in the main
    thread, such as Tkinter and Twisted, you have a problem

    Twisted supports Tkinter:

    tor.html#auto14

    It's better to use GUI with a real reactor available like GTK2 anyway
  • No.7 | | 175 bytes | |

    Lawrence wrote:
    It's better to use GUI with a real reactor available like GTK2
    anyway
    What's not real about Tkinter's?
    Regards,
    B
  • No.8 | | 197 bytes | |

    Bjoern Schliessmann <usenet-mail-0306.20.chr0n0ss (AT) spamgourmet (DOT) com>
    wrote:
    What's not real about Tkinter's?
    It's not a custom reactor as GTK's AFAIK
  • No.9 | | 654 bytes | |

    Tor Erik <torerik81 (AT) gmail (DOT) comwrites:
    I've developed an application were I've used Tkinter for the GUI.
    When I ran the GUI in another thread than the main, it kept locking
    up. I experienced similar problems with Twisted.

    Tkinter is not thread-safe. You have to synchronize any cross-thread
    communication with it. The way I usually do it is with an "after"
    method that checks a communications queue (Queue.Queue object) every
    20 msec or so. Any communication to and from the gui thread is done
    through the queue. There is a recipe like this in the Python Cookbook
    and you can probably find it at ASPN.

Re: Why not event-driven packages in other than the main thread?


max 4000 letters.
Your nickname that display:
In order to stop the spam: 4 + 4 =
QUESTION ON "Development"

EMSDN.COM