One thread freezes my whole application

Michael Zhang jianqiz at bigpond.com
Wed Sep 29 09:41:26 CEST 2004


My project uses Python-2.3.4 + Tkinter + PIL-1.1.4 to retrieve images 
from UDP server and display those images on a RedHat 9 box.

On my GUI there are two buttons: "connection button" is to create a 
connection to server, listen to any upcoming image packets, and write 
those data into a buffer; "display button" is to read the data from the 
buffer and display them in a infinite loop.

It's a natual approach to create two threads for each tasks (connection 
and display) from the base thread (GUI application).

The callback for the display button implements a Tkinter canvas.

The callback for the connection button is imported from a module created 
from a C function using swig-1.3.22.

For test purpose, I tried to invoke the display thread to display a 
image from a local file system and then invoke the connection thread to 
see if two threads can work separately.

The problem is when I click the connection button and invoke that 
connection thread, the whole application (including base thread and 
display thread) was frozen. What I expected was when one thread is 
listerning the socket, the display thread should be able to continue its 
running, and I should be able to invoke other (if any) threads from the 
GUI base thread. Afterwards, I had to use ps/kill to clean them up.

I'm quite new to Python. I started to learn Python and those libraries 
two months ago just after we chosed this project.

Here is my simplified code segments:

=============== Code segments Start ==============

class displayThread(threading.Thread):
     # the thread for displaying images
     def __init__(self, master):
	threading.Thread.__init__(self)
	self.master = master

     def run(self):
	UI(self.master)	 # create a Toplevel window to display

class connectionThread(threading.Thread):
     # the thread for connecting to server
     def __init__(self):
	threading.Thread.__init__(self)

     def run(self):
	Cmodule.create_connection() # Cmodule is created from C


class ControlPanel(Frame):
     # base GUI application from which all those threads are invoked
....
     def connect(self):
	# callback for connection button
	connectionThread().start()

     def display(self):
	# callback for display button
	top = Toplevel()
	displayThread(top).start()

=============== Code segments End ==============

What I'm thinking now is above threads code are quite standard and 
simple, there must be some other subtle issues beyond my knowledge.

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

Michael







More information about the Python-list mailing list