18.2. Monitoring IO

You can check for the ability to read from or write to a file (either a Python file or a lower level OS file) and then automatically invoke a callback. This is especially useful for networking applications. The function:

 
tag = input_add(source, condition, callback)

Where the first argument (source) is the open file (Python file object ot lower level file descriptor integer) you wish to have watched. The input_add() method uses the lower level file descriptor integer internally but the function will extract it from the Python file object using the fileno() method as needed. The second (condition) specifies what you want GDK to look for. This may be one of:

These are defined in GDK.py. As I'm sure you've figured out already, the third argument is the callback you wish to have called when the above conditions are satisfied.

The return value is a tag that may be used to stop the monitoring of the file by using the following function:
 
input_remove(tag)

The callback function should be similar to:
 
def input_callback(source, condition):

Where source and condition are as specified above. The source value will be the lower level file descriptor integer and not the Python file object (i.e. the value that is returned from the Python file method fileno()).