Threads -- play well with others? If not, what instead? (Summary)

Russell E. Owen owen at astro.washington.edu
Wed Jun 14 13:57:28 EDT 2000


In article <7Ta15.315$i06.94722 at ptah.visi.com>, Grant Edwards wrote:

>>...
>In Tk, you can assign read handlers to file objects.  Anytime
>there is data available to be read, the handler will be called.
>
>Just open the socket connection and assign a read-handler to
>it.  Piece-o-cake.  Here's an excerpt from a program that uses
>that technique to handle data from a popen2'd child process:
>
>------------------------------------------------------------
>
>if cmd is None:
>    exceptString = 'no executable specified'
>    raise exceptString, cmd
>                                        
>self.__returnCode = -1
>self.__child = popen2.Popen3(cmd)
>self.__fd = self.__child.fromchild.fileno()
>
>fcntl.fcntl(self.__fd, FCNTL.F_SETFD, FCNTL.O_NDELAY);
>
>
>Tkinter.tkinter.createfilehandler(self.__child.fromchild,
>                                  Tkinter.tkinter.READABLE,
>                                  self.__stdoutHandler)
>                                  
>------------------------------------------------------------
>
>self.__child.fromchild      is a file object connected to the "read" end 
>of a pipe.
>Tkinter.tkinter.READABLE    is a constant that tells Tk what you care 
>about.
>self.__stdoutHandler        is a function to call when the file object has 
>data available.
>...

Thank you very, very much. That was exactly the information I needed! I 
got a basic telnet application running on my mac pretty quickly once I 
had that, and can now (finally) see how to design a user interface 
system.

Oddly enough, I have "Python and TKInter Programming", and it says 
nothing at all about file handlers. I'm wondering what else I'm missing 
in Tkinter. If anyone can recommend any documentation that discusses 
createfilehandler and such, I'd love to know about it. (I did find it in 
a book on Tk, once I knew what to look for, but without this example I 
doubt I'd ever have figured out how to call it from Python even if I'd 
known about it.)

Regards,

-- Russell



More information about the Python-list mailing list