Python networking question

Russell E. Owen rowen at cesmail.net
Fri May 3 14:18:02 EDT 2002


I am writing a Python GUI networking client (presently in Tkinter, 
though I hope to switch to wxPython) and have a question...

What is the recommended way to do network I/O from Tkinter or wxPython?

Presently I'm using Tkinter file/socket events for read. This makes tons 
of sense to me. Data appears on the socket, triggering an event, calling 
my code. No wasted cpu cycles polling.

However, I haven't figured out how to do write properly. I'm afraid a 
simple blocking write may jam up my GUI if something goes wrong with the 
connection (but it's what I'm using now). I can't figure out how to make 
Tkinter file/socket event for write be useful. I'll have an occasional 
command to send, and meanwhile it seems silly for a file event on the 
socket to keep calling some routine of mine every time the socket is 
willing to accept output.

Should I use select instead, and does it even work with Tkinter's event 
loop or with wxPython? The fact that select uses a polling loop does not 
sound, on the face of it, very efficient. But on the other hand, it's 
completely standard -- the code wouldn't change if I switched GUI 
toolkits. And I think I basically understand how to do write with select 
(though sample code would be appreciated).

Any advice or pointers to advice (is there's a good book on the 
subject?) would be much appreciated.

-- Russell



More information about the Python-list mailing list