473,695 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multithreaded tkinter GUI application exception handling

My project uses Python-2.3.4 + Tkinter + PIL-1.1.4 to retrieve images
from server and display those images.

I created a thread (also a separate toplevel window) for displaying
images and another thread for recording the frame rates (using a
progress bar for visulization). The whole application worked very well
once it received image data from the socket.

The problem is when I tried to close that display window (click on the
standard "X" button on the right-upper corner), I got this exception:

--------
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/local/lib/python2.3/threading.py", line 436, in __bootstrap
self.run()
File "realtime.p y", line 188, in run
UI(self.master)
File "realtime.p y", line 238, in __init__
self.canvas.cre ate_image(0, 0, image=self.imag e, anchor=NW)
File "/usr/local/lib/python2.3/lib-tk/Tkinter.py", line 2060, in
create_image
return self._create('i mage', args, kw)
File "/usr/local/lib/python2.3/lib-tk/Tkinter.py", line 2049, in _create
return getint(self.tk. call(
TclError: invalid command name ".1080883980.10 80884908"
---------

Then after I closed the main windows, I got another exception:

---------
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/local/lib/python2.3/threading.py", line 436, in __bootstrap
self.run()
File "realtime.p y", line 198, in run
self.bar.update Progress(i)
File "/home/michael/usyd/soft3700/py/realtime/progressbar.py" , line
73, in updateProgress
self.update()
File "/home/michael/usyd/soft3700/py/realtime/progressbar.py" , line
91, in update
float(value) / self.max * self.width, self.height)
File "/usr/local/lib/python2.3/lib-tk/Tkinter.py", line 2039, in coords
self.tk.splitli st(
TclError: invalid command name
".1080881420.co nnectionPane.10 80883148.108088 3340"
---------

Why is the "TclError"? How can I handle those exceptions and exit the
applicaton gracefully?

Could someone help me out about those thread stuff? Thanks!

Michael

Jul 18 '05 #1
2 4385
Hello Michael,

Michael Zhang <ji*****@bigpon d.com> wrote in message news:<BF******* ************@ne ws-server.bigpond. net.au>...
... The problem is when I tried to close that display window (click on the
standard "X" button on the right-upper corner), I got this exception: ...
Could someone help me out about those thread stuff? Thanks!


I also had the same exception, but I can't remember what was the
reason. You can look at my working code, maybe it can help:

http://uucode.com/texts/pylongopgui/pyguiapp.html
A complete Python Tkinter application demonstrates one of the ways to
implement a good GUI wrapper for a long operation: with a progress
bar, log messages, cancelling.

--
Oleg
Jul 18 '05 #2
Michael Zhang wrote:
My project uses Python-2.3.4 + Tkinter + PIL-1.1.4 to retrieve images
from server and display those images.

I created a thread (also a separate toplevel window) for displaying
images and another thread for recording the frame rates (using a
progress bar for visulization). The whole application worked very well
once it received image data from the socket.

The problem is when I tried to close that display window (click on the
standard "X" button on the right-upper corner), I got this exception:

--------
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/local/lib/python2.3/threading.py", line 436, in __bootstrap
self.run()
File "realtime.p y", line 188, in run
UI(self.master)
File "realtime.p y", line 238, in __init__
self.canvas.cre ate_image(0, 0, image=self.imag e, anchor=NW)
File "/usr/local/lib/python2.3/lib-tk/Tkinter.py", line 2060, in
create_image
return self._create('i mage', args, kw)
File "/usr/local/lib/python2.3/lib-tk/Tkinter.py", line 2049, in _create
return getint(self.tk. call(
TclError: invalid command name ".1080883980.10 80884908"
---------
Not knowing your application exactly, I can only guess what's happening: it
seems that your secondary thread is not aware that the window is closed and it
still tries to draw things in a canvas that has already been destroyed (module
realtime.py, line 238, according to the traceback).

So you should either make sure your secondary thread is stopped before the
window is closed, or enclose the canvas.create_i mage in a try except handling
the TclError. This last solution is far from optimal, since any mistake in a
Tkinter call always raises a TclError, so you may catch other errors as well.
I'd go for the first, using for example an Event (in module threading) to
indicate the window is closed.
Then after I closed the main windows, I got another exception:

---------
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/local/lib/python2.3/threading.py", line 436, in __bootstrap
self.run()
File "realtime.p y", line 198, in run
self.bar.update Progress(i)
File "/home/michael/usyd/soft3700/py/realtime/progressbar.py" , line
73, in updateProgress
self.update()
File "/home/michael/usyd/soft3700/py/realtime/progressbar.py" , line
91, in update
float(value) / self.max * self.width, self.height)
File "/usr/local/lib/python2.3/lib-tk/Tkinter.py", line 2039, in coords
self.tk.splitli st(
TclError: invalid command name
".1080881420.co nnectionPane.10 80883148.108088 3340"
---------

Why is the "TclError"? How can I handle those exceptions and exit the
applicaton gracefully?
Same problem here, this time for the progress bar apparently: you try to do
things in a widget that is already destroyed.

BTW, mixing Tkinter calls in several threads is not a good idea: Tkinter is not
thread-safe and I experienced quite a lot of crashes when trying to do that. The
best solution I could find was to handle all the GUI stuff in the main thread
and make the secondary threads post events in Tkinter's event queue via the
event_generate method to serialize things at GUI level. I'm quite surprised to
hear that you succeeded in making things work, but be aware that you may
experience weird crashes in the future...
Could someone help me out about those thread stuff? Thanks!

Michael


HTH
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2336
by: Daniel Wilson | last post by:
I am having exception-handling and stability problems with .NET. I will have a block of managed code inside try...catch and will still get a generic ..NET exception box that will tell me which assemblies are loaded before shutting down. In one case, some of my DB-accessing code didn't handle a NULL value properly. But try...catch wouldn't catch the exception and keep going. I'd just get the error message and then it would shut the...
7
6000
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
1
1971
by: Noor | last post by:
Hi all, I am trying to catch all types of exceptions from a app regardless of whether it is in debugger mode( VS development environment) or run the.exe file outside the IDE. My App contains the thousand of classes and I do not want to use the Try Catch block in each class. Because it is logically similar to GOTO statement. I want to prevent exception from being swallowed.
13
2311
by: tolisss | last post by:
Hi i have setup a global exception handler b4 Application.Run like Application.ThreadException += new ThreadExceptionEventHandler(GlobalExceptionProcessing.AppThreadException ); then after Application.Run(new Form1()); i have setup a global keyboard hook
11
5587
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
4
1526
by: MadSage | last post by:
I currently have a multi-threaded server application with worker threads and a core thread. For all of these threads I have something like the following code: uint32 __stdcall CCore::EntryPoint(void *pV) { CCore *pCore = (CCore *)pV; try {
16
2538
by: Chuck Cobb | last post by:
I'm implementing a centralized exception handling routine using the Enterprise Library Exception Management Application Block. I trap all unhandled exceptions to one place using the following method: // --- Create an Exception Handler for Thread Exceptions ---------------- Application.ThreadException += new ThreadExceptionEventHandler(OnThreadException);
5
3829
by: Bry | last post by:
I've created a class that offers an enhanced way of handling fatal exceptions. The class allows the user to optionaly submit a http based anonymous error report to myself, and also records details in the application log. The static method is overloaded, and supports passing exceptions and/or strings just like throwing an exception.The class will also fall back to the standard exception handling if something goes wrong in my class. As an...
1
3383
by: Tom Berger | last post by:
Just a short question concerning exception handling.... All of my applications contain an event handling in the Main() like this one: static void Main() { // declare global exeption handler Application.ThreadException += new
0
8649
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8586
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8864
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4351
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2289
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.