Python Glossary Русский

Python 3.13+Linux · macOSosfunction

os.ptsname

os — pseudo-terminals (pty)

Return the path of the slave pseudo-terminal (by master fd). Availability: Unix.

Syntax

os.ptsname(...)

It returns the slave device path, such as '/dev/pts/4', from the master descriptor. The child opens this path to make it its terminal. Call it after unlockpt; for a descriptor that is not a pseudo-terminal master it raises OSError.

Examples

import os
master = os.posix_openpt(os.O_RDWR)  # → ? только Unix: master-дескриптор псевдотерминала
print(os.ptsname(master))  # → ? только Unix: путь парного slave-устройства, например /dev/pts/4
os.unlockpt(master)  # → ? только Unix: разблокировали slave перед открытием
slave = os.open(os.ptsname(master), os.O_RDWR)  # → ? только Unix: именно по пути от ptsname и открывают slave
print(os.ptsname(0))  # → OSError — дескриптор stdin не является master-устройством pty

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy