-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync_pty.py
More file actions
34 lines (26 loc) · 996 Bytes
/
async_pty.py
File metadata and controls
34 lines (26 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from __future__ import annotations
import asyncio
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from leap0 import AsyncLeap0Client, AsyncPtyConnection, AsyncSandbox, PtySession
async def main() -> None:
async with AsyncLeap0Client() as client:
sandbox: AsyncSandbox = await client.sandboxes.create()
try:
session: PtySession = await sandbox.pty.create(
session_id="async-demo-terminal",
cols=120,
rows=30,
cwd="/home/user",
)
connection: AsyncPtyConnection = await sandbox.pty.connect(session.id)
try:
await connection.send("pwd\n")
print((await connection.recv()).decode("utf-8", errors="replace"))
finally:
await connection.close()
finally:
await sandbox.delete()
if __name__ == "__main__":
asyncio.run(main())