python - How to make tkinter repond events while waiting socket data? -
I am trying to create an app reading data from a socket, but it takes some time and lock the interface Does, how do I respond to vaccine events while waiting?
It's easy! And you do not even want threads! But you have to make your I / O code a bit smaller. TC is equivalent to the EXTaddyPop () call of XT, which allows you to register a callback function which will be called from mainstream if I / O is possible on the ISO fileliver. This is what you need: Tkinter import tkinter tkinter.createfilehandler (file, mask, callback) from
The file is a python file or socket object (Actually, anything with a fileno () method), or an integer file is one of the descriptor mask constants. RADAB or tacenator. Callback is said to be as follows:
callback (file, mask)
When you are done, callback must be unearned
Note: Because you do not know how many bytes are available to read, you can not read or use the Python file object. Readline methods, because they insist on reading a predefined number bytes. Chairs, recv () or recvfrom () methods will work fine; For other files, use os.read (file.fileno (), maxbytecount).
Comments
Post a Comment