获取 ttyname 时 Python 崩溃
我正在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pty.openpty
调用 os.openpty主端仅由文件描述符表示,而从端由/dev中的文件表示。
pty.openpty
calls os.openptyThe master end is represented by a file descriptor only, whereas the slave end is represented by a file in /dev.