This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Jackmoo
Recipients Jackmoo, PythonInTheGrass, brian.curtin, cgohlke, docs@python, terry.reedy
Date 2015-05-24.11:57:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1432468655.17.0.675376900407.issue11029@psf.upfronthosting.co.za>
In-reply-to
Content
Hi there, recently I also encounter this in windows(7), and my python program occasionally crash and the windows pops 'appcrash' message with tcl8.5.dll error c000005 (access violation).

And this end up related to thread safe problem described as above. Since in my program, I have to build the tkinter UI in another thread (main thread was occupied by other module which blocking), so I can't follow the 'build UI in main thread' solution. My work around is, add a handler which using .after() and get_nowait() to call itself periodically to handle the command in queue.

def commandQueueHandler(self):
    try:
        while 1:
            your_command = self.textCommandQueue.get_nowait()
            if your_command is not None:
                # execute the command ....
            self.Text.update_idletasks()
    except Queue.Empty:
        pass
    self.Text.after(100, self.commandQueueHandler)

Once this method is triggered, just build another thread to put() command in textCommandQueue, then it will be executed periodically.
One thing that should mention is the update_idletasks() should be added after each command execution, otherwise the UI refresh will be slower then expected. (in my case, the scrolling of Text widge is a bit 'sticky' when I pull it. After adding update_idletasks(), it becomes smoother.)

TL:DR,
If you have to run tkinter UI in another thread, add a queue and self-called method with after() and get_nowait() in UI thread to handle the queue. If you want to send command to UI at other thread, just put() the command in the queue of UI thread.
History
Date User Action Args
2015-05-24 11:57:35Jackmoosetrecipients: + Jackmoo, terry.reedy, brian.curtin, cgohlke, docs@python, PythonInTheGrass
2015-05-24 11:57:35Jackmoosetmessageid: <1432468655.17.0.675376900407.issue11029@psf.upfronthosting.co.za>
2015-05-24 11:57:35Jackmoolinkissue11029 messages
2015-05-24 11:57:34Jackmoocreate