Pty#
Superclasses: Object
Implemented Interfaces: Initable
- Constructors:
Pty(**properties)
new_foreign_sync(fd:int, cancellable:Gio.Cancellable=None) -> Vte.Pty
new_sync(flags:Vte.PtyFlags, cancellable:Gio.Cancellable=None) -> Vte.Pty
Constructors#
- class Pty
- classmethod new_foreign_sync(fd: int, cancellable: Cancellable | None = None) Pty #
Creates a new
Pty
for the PTY masterfd
.No entry will be made in the lastlog, utmp or wtmp system files.
Note that the newly created
Pty
will take ownership offd
and close it on finalize.- Parameters:
fd – a file descriptor to the PTY
cancellable – a
Cancellable
, orNone
- classmethod new_sync(flags: PtyFlags, cancellable: Cancellable | None = None) Pty #
Allocates a new pseudo-terminal.
You can later use fork() or the
spawn_async()
family of functions to start a process on the PTY.If using fork(), you MUST call
child_setup()
in the child.If using
spawn_async()
and friends, you MUST either usechild_setup()
directly as the child setup function, or callchild_setup()
from your own child setup function supplied.When using
spawn_sync()
with a custom child setup function,child_setup()
will be called before the supplied function; you must not call it again.Also, you MUST pass the %G_SPAWN_DO_NOT_REAP_CHILD flag.
Note also that %G_SPAWN_STDOUT_TO_DEV_NULL, %G_SPAWN_STDERR_TO_DEV_NULL, and %G_SPAWN_CHILD_INHERITS_STDIN are not supported, since stdin, stdout and stderr of the child process will always be connected to the PTY.
Note that you should set the PTY’s size using
set_size()
before spawning the child process, so that the child process has the correct size from the start instead of starting with a default size and then shortly afterwards receiving aSIGWINCH
signal. You should prefer usingpty_new_sync()
which does this automatically.- Parameters:
flags – flags from
PtyFlags
cancellable – a
Cancellable
, orNone
Methods#
- class Pty
-
- close() None #
Since 0.42 this is a no-op.
Deprecated since version 0.42: Please do not use it in newly written code
- get_size() Tuple[bool, int, int] #
Reads the pseudo terminal’s window size.
If getting the window size failed,
error
will be set to aIOError
.
- set_size(rows: int, columns: int) bool #
Attempts to resize the pseudo terminal’s window size. If successful, the OS kernel will send
SIGWINCH
to the child process group.If setting the window size failed,
error
will be set to aIOError
.- Parameters:
rows – the desired number of rows
columns – the desired number of columns
- set_utf8(utf8: bool) bool #
Tells the kernel whether the terminal is UTF-8 or not, in case it can make use of the info. Linux 2.6.5 or so defines IUTF8 to make the line discipline do multibyte backspace correctly.
- Parameters:
utf8 – whether or not the pty is in UTF-8 mode
- spawn_async(working_directory: str | None, argv: list[str], envv: list[str] | None, spawn_flags: SpawnFlags, child_setup: Callable[[Any], None] | None, timeout: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Like
spawn_with_fds_async()
, except that this function does not allow passing file descriptors to the child process. Seespawn_with_fds_async()
for more information.Added in version 0.48.
- Parameters:
working_directory – the name of a directory the command should start in, or
None
to use the current working directoryargv – child’s argument vector
envv – a list of environment variables to be added to the environment before starting the process, or
None
spawn_flags – flags from
SpawnFlags
child_setup – an extra child setup function to run in the child just before exec(), or
None
timeout – a timeout value in ms, -1 for the default timeout, or G_MAXINT to wait indefinitely
cancellable – a
Cancellable
, orNone
callback – a
AsyncReadyCallback
, orNone
user_data – user data for
callback
- spawn_finish(result: AsyncResult) Tuple[bool, int] #
Added in version 0.48.
- Parameters:
result – a
AsyncResult
- spawn_with_fds_async(working_directory: str | None, argv: list[str], envv: list[str] | None, fds: list[int] | None, map_fds: list[int] | None, spawn_flags: SpawnFlags, child_setup: Callable[[Any], None] | None, timeout: int, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Starts the specified command under the pseudo-terminal
pty
. Theargv
andenvv
lists should beNone
-terminated. The “TERM” environment variable is automatically set to a default value, but can be overridden fromenvv
.pty_flags
controls logging the session to the specified system log files.Note also that %G_SPAWN_STDOUT_TO_DEV_NULL, %G_SPAWN_STDERR_TO_DEV_NULL, and %G_SPAWN_CHILD_INHERITS_STDIN are not supported in
spawn_flags
, since stdin, stdout and stderr of the child process will always be connected to the PTY. Also %G_SPAWN_LEAVE_DESCRIPTORS_OPEN is not supported; and %G_SPAWN_DO_NOT_REAP_CHILD will always be added tospawn_flags
.If
fds
is notNone
, the child process will map the file descriptors fromfds
according tomap_fds
;n_map_fds
must be less or equal ton_fds
. This function will take ownership of the file descriptors infds
; you must not use or close them after this call. All file descriptors infds
must have the FD_CLOEXEC flag set on them; it will be unset in the child process before calling man:execve(2). Note also that no file descriptor may be mapped to stdin, stdout, or stderr (file descriptors 0, 1, or 2), since these will be assigned to the PTY. All open file descriptors apart from those mapped as above will be closed when execve() is called.Beginning with 0.60, and on linux only, and unless
SPAWN_NO_SYSTEMD_SCOPE
is passed inspawn_flags
, the newly created child process will be moved to its own systemd user scope; and ifSPAWN_REQUIRE_SYSTEMD_SCOPE
is passed, and creation of the systemd user scope fails, the whole spawn will fail. You can override the options used for the systemd user scope by providing a systemd override file for ‘vte-spawn-.scope’ unit. See man:systemd.unit(5) for further information.See vte_pty_new(), and
watch_child()
for more information.Added in version 0.62.
- Parameters:
working_directory – the name of a directory the command should start in, or
None
to use the current working directoryargv – child’s argument vector
envv – a list of environment variables to be added to the environment before starting the process, or
None
fds – an array of file descriptors, or
None
map_fds – an array of integers, or
None
spawn_flags – flags from
SpawnFlags
child_setup – an extra child setup function to run in the child just before exec(), or
None
timeout – a timeout value in ms, -1 for the default timeout, or G_MAXINT to wait indefinitely
cancellable – a
Cancellable
, orNone
callback – a
AsyncReadyCallback
, orNone
user_data – user data for
callback