Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Tkinter.Canvas thread safety problem?

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


zdenekmaxa at yahoo

Jul 7, 2009, 5:38 AM

Post #1 of 3 (200 views)
Permalink
Tkinter.Canvas thread safety problem?

Hello,

I have started a project using Tkinter. The application performs some
regular checks in a thread and updates Canvas components. I have
observed that sometimes the application hangs when it is about to call
canvas.itemconfig() when the thread is about to terminate in the next loop.

Experimenting with this problem for a while, I have compiled a little
example which always reproduces the problem. Commenting out the line 52
(before canvas.itemconfig()), the example always finishes all right,
having the delay there, it hangs.

I would like to ask if you could have a look at the snippet in the
attachment and tell me if that is actually me doing something wrong or
indeed Tkinter thread safety problem and what the workaround could be.

Could you please also comment on wxPython thread safety?

I am using:

Python 2.5.4 (r254:67916, Feb 17 2009, 20:16:45)
[GCC 4.3.3]

2.6.26-1-amd64 #1 SMP Fri Mar 13 19:34:38 UTC 2009 x86_64 GNU/Linux

Thanks in advance,
Zdenek
Attachments: tkinter_thread_safety.py (2.15 KB)


deets at nospam

Jul 7, 2009, 6:23 AM

Post #2 of 3 (186 views)
Permalink
Re: Tkinter.Canvas thread safety problem? [In reply to]

Zdenek Maxa wrote:

> Hello,
>
> I have started a project using Tkinter. The application performs some
> regular checks in a thread and updates Canvas components. I have
> observed that sometimes the application hangs when it is about to call
> canvas.itemconfig() when the thread is about to terminate in the next
> loop.
>
> Experimenting with this problem for a while, I have compiled a little
> example which always reproduces the problem. Commenting out the line 52
> (before canvas.itemconfig()), the example always finishes all right,
> having the delay there, it hangs.
>
> I would like to ask if you could have a look at the snippet in the
> attachment and tell me if that is actually me doing something wrong or
> indeed Tkinter thread safety problem and what the workaround could be.
>
> Could you please also comment on wxPython thread safety?
>

As a rule of thumb, GUI-toolkits aren't threadsafe. Qt being a notable
exception to this rule.

There are various ways to cope with this, mostly through injecting events
into the event-queue of the main gui thread, or using timers.

This is also true for wx (google wx python threading for a plethora of
information on this)

For Tx, I dimly remember an "after" function that can be used to invoke
timer-based code. Use that to update aggregated data from the events.

Diez
--
http://mail.python.org/mailman/listinfo/python-list


__peter__ at web

Jul 7, 2009, 6:50 AM

Post #3 of 3 (186 views)
Permalink
Re: Tkinter.Canvas thread safety problem? [In reply to]

Zdenek Maxa wrote:

> I would like to ask if you could have a look at the snippet in the
> attachment and tell me if that is actually me doing something wrong or
> indeed Tkinter thread safety problem and what the workaround could be.

http://effbot.org/zone/tkinter-threads.htm

--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.