简体   繁体   English

如何找到 pythons os.openpty() function 的源代码

[英]How do I find the source code for pythons os.openpty() function

I am trying to better understand how to write a linux terminal emulator in python.我试图更好地理解如何在 python 中编写 linux 终端仿真器。 When looking at the module source code for pty.py , it appears that pty.openpty() is a wrapper for os.openpty() .查看pty.py的模块源代码时,似乎pty.openpty()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().但是当我查看os.py模块源代码时,没有名为openpty()的function。 In fact, I am unable to find the source code for os.openpty() anywhere in the cpython codebase.事实上,我无法在 cpython 代码库的任何地方找到 os.openpty() 的源代码。 What am I missing?我错过了什么?

But when I look through the os.py module source code, there is no function named openpty().但是当我查看os.py模块源代码时,没有名为openpty()的function。 In fact, I am unable to find the source code for os.openpty() anywhere in the cpython codebase.事实上,我无法在 cpython 代码库的任何地方找到 os.openpty() 的源代码。 What am I missing?我错过了什么?

You have to search for the string os.openpty in all files of the Python source distribution you should have available locally on your computer ( you will find more details and help in the comment to your question provided by wkl ).您必须在 Python 源代码分发的所有文件中搜索字符串os.openpty ,您应该在您的计算机上本地可用(您将在 wkl 提供的对您的问题的评论中找到更多详细信息和帮助)。

This will give you for example with Linux grep posixmodule.c:7176:os.openpty as the result leading to:例如,这将为您提供 Linux grep posixmodule.c:7176:os.openpty结果导致:

#if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)
/*[clinic input]

os.openpty

Open a pseudo-terminal.

Return a tuple of (master_fd, slave_fd) containing open file descriptors
for both the master and slave ends.
[clinic start generated code]*/

static PyObject *
os_openpty_impl(PyObject *module)
/*[clinic end generated code: output=98841ce5ec9cef3c input=f3d99fd99e762907]*/

where you see that os.openpty is mapped to os_openpty_impl .您在哪里看到os.openpty映射到os_openpty_impl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM