IOChannel

class IOChannel(*args, **kwargs)

The GIOChannel data type aims to provide a portable method for using file descriptors, pipes, and sockets, and integrating them into the main event loop (see MainContext). Currently, full support is available on UNIX platforms; support for Windows is only partially complete.

To create a new GIOChannel on UNIX systems use unix_new. This works for plain file descriptors, pipes and sockets. Alternatively, a channel can be created for a file in a system independent manner using new_file.

Once a GIOChannel has been created, it can be used in a generic manner with the functions read_chars, write_chars, seek_position, and shutdown.

To add a GIOChannel to the main event loop, use io_add_watch or io_add_watch_full. Here you specify which events you are interested in on the GIOChannel, and provide a function to be called whenever these events occur.

GIOChannel instances are created with an initial reference count of 1. ref and unref can be used to increment or decrement the reference count respectively. When the reference count falls to 0, the GIOChannel is freed. (Though it isn’t closed automatically, unless it was created using new_file.) Using io_add_watch or io_add_watch_full increments a channel’s reference count.

The new functions read_chars, read_line, read_line_string, read_to_end, write_chars, seek_position, and flush should not be mixed with the deprecated functions read, write, and seek on the same channel.

Methods

class IOChannel
add_watch(condition, callback, *user_data, **kwargs)
Parameters:
  • condition

  • callback

  • user_data

  • kwargs

next()
read(max_count=-1)

Reads data from a IOChannel.

Deprecated since version 2.2: Use read_chars() instead.

Parameters:

max_count

readline(size_hint=-1)
Parameters:

size_hint

readlines(size_hint=-1)
Parameters:

size_hint

seek(offset, whence=0)

Sets the current position in the IOChannel, similar to the standard library function fseek().

Deprecated since version 2.2: Use seek_position() instead.

Parameters:
  • offset – an offset, in bytes, which is added to the position specified by type

  • whence

write(buf, buflen=-1)

Writes data to a IOChannel.

Deprecated since version 2.2: Use write_chars() instead.

Parameters:
  • buf – the buffer containing the data to write

  • buflen

writelines(lines)
Parameters:

lines