Threads and Tkinter GUI ...

Arild Hansen arildh at stud.cs.uit.no
Mon Oct 23 05:22:11 EDT 2000


Hello,

I have made an xclient using Tkinter. I start my xclient and a nifty
looking GUI appears. The client acts as a userinterface to a phone
application. It is therefore essential that when the client starts, it
first checks if it is able to connect to a server (which I also
implemented) and then the client checks every five minutes or so if it
is still connected to the server (a simple ping operation). So here is
what I want: When I start the xclient I first create a thread called
"pingServer" which is resonsible for pinging the server at regular
intervals. When this thread is started I start the GUI's mainloop.
I will then have a GUI running and a thread running in the background
pinging the server. If the server is not found, the pingServer thread
will update a global variable and a led light will turn red in the GUI.

Here is my problem: It all works just fine except that when I start the
pingServer thread, it only executes it's first command (being something
like print 'pingServer started'). Then the GUI starts and the pingServer
thread does nothing until I exit my GUI. When I close my GUI the rest of
the pingServer thread is executed correctly.

My question is: Why does this happen? Is there something special to know
about the GUI mainloop() and thread scheduling? Why can't a simple
thread run alongside with GUI mainloop()?

I have tried to start my pingServer thread at diferent locations: I have
tried to start it before I execute the GUI mainloop() in __main__, I
have tried to execute it from inside the GUI classes etc.

I'll appreciate all help as I don't figure out how to get around this
problem. I run my program on Linux RedHat 6.2. All code has been tested
and works fine (i.e. the thread starts and run fine if I don't start my
GUI etc. I have done a lot of testing so I think the code is just about
perfect :-)

Well. hopefully someone out there will know what to do.

Arild Hansen




More information about the Python-list mailing list