Tkinter and threads

Discussion in 'Python' started by Boman Romain, May 4, 2004.

  1. Boman Romain

    Boman Romain Guest

    Hi everyone,
    I've got problems with Tkinter and threads when using a debug version of
    python.
    I would like to build a "GUI thread" and an "interpreter thread" (the
    classical python command line). Both threads don't interact with each other
    (for now).
    The GUI must be in a separate thread because the user can execute commands
    that take a long time to run through the command line (and the GUI must be
    available during these commands)

    For example: (file: mygui.py)

    import threading
    import Tkinter

    class RWin (threading.Thread):
    def __init__(self):
    threading.Thread.__init__(self)

    def run(self, *args):
    self.root = Tkinter.Tk()
    print 'starting Tk!'
    self.root.mainloop()

    bw = RWin()
    bw.start()


    when I load this file (import mygui), the tk window opens and everything is
    OK if I use a non-debug version of python.
    Otherwise (with a debug version), python_d crashes when I press a key with
    this message : "Fatal python error: invalid thread state for this thread"

    It seams that the problem comes from the EventHook() function defined by
    tkinter. This function is called by the main thread (the interpreter)
    because tkinter uses PyOS_InputHook (for managing things I don't
    understand). This function calls RestoreThread() with the Tk thread state
    instead of the main thread state. As the debug version checks these states,
    it fails.

    What is wrong? Is it impossible to have these two threads working toegether
    (in a debug version of python)?


    Romain
     
    Boman Romain, May 4, 2004
    #1
    1. Advertising

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. Julia Goolia

    tkinter, sockets and threads together

    Julia Goolia, Sep 11, 2003, in forum: Python
    Replies:
    4
    Views:
    540
    Steve Holden
    Sep 12, 2003
  2. Replies:
    5
    Views:
    599
    Eric Brunel
    Feb 12, 2004
  3. Rod Stephenson
    Replies:
    0
    Views:
    448
    Rod Stephenson
    Jun 22, 2004
  4. Nir Aides

    tkinter and threads

    Nir Aides, May 4, 2005, in forum: Python
    Replies:
    1
    Views:
    337
    Philippe C. Martin
    May 4, 2005
  5. Une bévue
    Replies:
    0
    Views:
    172
    Une bévue
    Jun 14, 2006
Loading...

Share This Page