AWS lambda:pty 设备不足
我尝试在 AWS lambda 中使用 pexpect 库,但收到以下错误:
[ERROR] OSError: out of pty devices
事实证明,任何包含 pty.spawn() 的代码在 lambda 中都会失败。下面是失败的 lambda 的最小代码:
import json
import pty
def lambda_handler(event, context):
pty.spawn('ls')
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
等效的期望代码也非常基本:
cmd = f'sftp -i my_key_file -q username@server'
child = pexpect.spawn(cmd, encoding='utf-8')
产生的异常是:
[ERROR] OSError: out of pty devices
Traceback (most recent call last):
...
child = pexpect.spawn(...)
File "/var/lang/lib/python3.7/site-packages/pexpect/pty_spawn.py", line 205, in __init__
self._spawn(command, args, preexec_fn, dimensions)
File "/var/lang/lib/python3.7/site-packages/pexpect/pty_spawn.py", line 304, in _spawn
cwd=self.cwd, **kwargs)
File "/var/lang/lib/python3.7/site-packages/pexpect/pty_spawn.py", line 315, in _spawnpty
return ptyprocess.PtyProcess.spawn(args, **kwargs)
File "/var/lang/lib/python3.7/site-packages/ptyprocess/ptyprocess.py", line 230, in spawn
pid, fd = pty.fork()
File "/var/lang/lib/python3.7/pty.py", line 96, in fork
master_fd, slave_fd = openpty()
File "/var/lang/lib/python3.7/pty.py", line 29, in openpty
master_fd, slave_name = _open_terminal()
File "/var/lang/lib/python3.7/pty.py", line 59, in _open_terminal
raise OSError('out of pty devices')
[ERROR] OSError: out of pty devices Traceback (most recent call last):
I'm trying to use the pexpect library within an AWS lambda, but I'm getting the following error:
[ERROR] OSError: out of pty devices
It turns out that any code that contains pty.spawn() fails in a lambda. Here's a minimal piece of code for a failing lambda:
import json
import pty
def lambda_handler(event, context):
pty.spawn('ls')
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
The equivalent expect code is also pretty basic:
cmd = f'sftp -i my_key_file -q username@server'
child = pexpect.spawn(cmd, encoding='utf-8')
The resulting exception is:
[ERROR] OSError: out of pty devices
Traceback (most recent call last):
...
child = pexpect.spawn(...)
File "/var/lang/lib/python3.7/site-packages/pexpect/pty_spawn.py", line 205, in __init__
self._spawn(command, args, preexec_fn, dimensions)
File "/var/lang/lib/python3.7/site-packages/pexpect/pty_spawn.py", line 304, in _spawn
cwd=self.cwd, **kwargs)
File "/var/lang/lib/python3.7/site-packages/pexpect/pty_spawn.py", line 315, in _spawnpty
return ptyprocess.PtyProcess.spawn(args, **kwargs)
File "/var/lang/lib/python3.7/site-packages/ptyprocess/ptyprocess.py", line 230, in spawn
pid, fd = pty.fork()
File "/var/lang/lib/python3.7/pty.py", line 96, in fork
master_fd, slave_fd = openpty()
File "/var/lang/lib/python3.7/pty.py", line 29, in openpty
master_fd, slave_name = _open_terminal()
File "/var/lang/lib/python3.7/pty.py", line 59, in _open_terminal
raise OSError('out of pty devices')
[ERROR] OSError: out of pty devices Traceback (most recent call last):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论