获取 ttyname 时 Python 崩溃

发布于 2025-01-12 15:09:56 字数 510 浏览 2 评论 0原文

我正在 Mac OS 上用 Python 创建一个伪终端对,然后尝试获取它们的名称。

import os
import pty

master, slave = pty.openpty()

print(os.ttyname(slave))
print(os.ttyname(master))

我可以获得从属服务器,但在尝试获取主服务器时 Python 崩溃了。

$ python --version
Python 3.9.10
$ python shim/tunnel.py
/dev/ttys009
Traceback (most recent call last):
  File "/Users/tamlyn/projects/shim/tunnel.py", line 7, in <module>
    print(os.ttyname(master))
OSError: [Errno 34] Result too large

为什么会发生这种情况?

I'm creating a pseudo terminal pair in Python, on Mac OS, and then trying to get their names.

import os
import pty

master, slave = pty.openpty()

print(os.ttyname(slave))
print(os.ttyname(master))

I can get the slave one but Python crashes when trying to get the master one.

$ python --version
Python 3.9.10
$ python shim/tunnel.py
/dev/ttys009
Traceback (most recent call last):
  File "/Users/tamlyn/projects/shim/tunnel.py", line 7, in <module>
    print(os.ttyname(master))
OSError: [Errno 34] Result too large

Why is this happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往日情怀 2025-01-19 15:09:56

pty.openpty 调用 os.openpty

os.openpty()

打开一个新的伪终端对。分别返回 pty 和 tty 的一对文件描述符(主、从)。新的文件描述符是不可继承的。对于(稍微)更便携的方法,请使用 pty 模块。

主端仅由文件描述符表示,而从端由/dev中的文件表示。

pty.openpty calls os.openpty

os.openpty()

Open a new pseudo-terminal pair. Return a pair of file descriptors (master, slave) for the pty and the tty, respectively. The new file descriptors are non-inheritable. For a (slightly) more portable approach, use the pty module.

The master end is represented by a file descriptor only, whereas the slave end is represented by a file in /dev.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文