I am trying to better understand how to write a linux terminal emulator in python. When looking at the module source code for pty.py, it appears that pty.openpty() is a wrapper for os.openpty().
def openpty():
"""openpty() -> (master_fd, slave_fd)
Open a pty master/slave pair, using os.openpty() if possible."""
try:
return os.openpty()
except (AttributeError, OSError):
pass
master_fd, slave_name = _open_terminal()
slave_fd = slave_open(slave_name)
return master_fd,
But when I look through the os.py module source code, there is no function named openpty(). In fact, I am unable to find the source code for os.openpty() anywhere in the cpython codebase. What am I missing?
openptyin the CPython source, and it's not implemented in Python. It's C code inposixmodule.c :: os_openpty_implos.openptyclearly existing in the codebase, the search function in github does not return this file as a result.man openptywill give you more information.clinicin the source). Also see: docs.python.org/3/c-api/index.html