[Tutor] Problem with threads

Kent Johnson kent37 at tds.net
Mon Feb 27 01:04:35 CET 2006


David Cohen wrote:
> Hi,
> 
> Here is the code attached. It is a simple test program that open a gtk
> window and connect to a server (might be an irc or telnet server).
> When the button "Connect" is clicked, the thread (should) starts and
> read what is coming from the server. But it never happens... just when
> I click on the "Disconnect" button and the join() function is called.
> Did you get any problem like that?

Ok. I've never worked with gtk, but in GUI frameworks it can be a bad 
idea to change the gui from a thread other than the event thread, which 
is what you are doing. My guess is that the socket thread is running but 
the gui is not updating until you click disconnect and change the gui 
from the event thread.

The first thing I would try is, put a print in GetSockData.run() to see 
if it is doing anything (my guess is you will see the print).

If that works, then you need to learn how to make threads and gtk play 
together. Here is a tutorial that might help - the first example is 
pretty close to what you are doing:
http://www.pardon-sleeuwaegen.be/antoon/python/page0.html

This FAQ entry (from Google's cache, the main site is not responding) 
shows another way:
http://64.233.179.104/search?q=cache:fVAyfmzgtFoJ:www.async.com.br/faq/pygtk/index.py%3Freq%3Dshow%26file%3Dfaq20.006.htp+pygtk+thread&hl=en&gl=us&ct=clnk&cd=7&client=firefox-a

HTH,
Kent



More information about the Tutor mailing list