aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-cli/src/meshbay_cli/tui/clipboard.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-cli/src/meshbay_cli/tui/clipboard.py')
-rw-r--r--packages/meshbay-cli/src/meshbay_cli/tui/clipboard.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/packages/meshbay-cli/src/meshbay_cli/tui/clipboard.py b/packages/meshbay-cli/src/meshbay_cli/tui/clipboard.py
index 1a1f0d7..e0bd315 100644
--- a/packages/meshbay-cli/src/meshbay_cli/tui/clipboard.py
+++ b/packages/meshbay-cli/src/meshbay_cli/tui/clipboard.py
@@ -12,6 +12,7 @@ skipped, never an error.
import asyncio
import os
import shutil
+import subprocess
import sys
TIMEOUT = 3.0
@@ -40,24 +41,25 @@ def _encode(text: str) -> bytes:
return ("" + text).encode("utf-16-le") if sys.platform == "win32" else text.encode()
-async def _run(cmd: list[str], data: bytes | None) -> bytes | None:
+def _run_blocking(cmd: list[str], data: bytes | None) -> bytes | None:
if shutil.which(cmd[0]) is None:
return None
env = {**os.environ, "LC_CTYPE": "UTF-8"} if sys.platform == "darwin" else None
try:
- proc = await asyncio.create_subprocess_exec(
- *cmd, stdin=asyncio.subprocess.PIPE if data is not None else asyncio.subprocess.DEVNULL,
- stdout=asyncio.subprocess.PIPE if data is None else asyncio.subprocess.DEVNULL,
- stderr=asyncio.subprocess.DEVNULL, env=env)
- except OSError:
- return None
- try:
- out, _ = await asyncio.wait_for(proc.communicate(data), TIMEOUT)
- except TimeoutError:
- proc.kill()
- await proc.wait()
+ proc = subprocess.run(
+ cmd, input=data, stdin=None if data is not None else subprocess.DEVNULL,
+ stdout=subprocess.PIPE if data is None else subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL, env=env, timeout=TIMEOUT,
+ creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0))
+ except (OSError, subprocess.TimeoutExpired):
return None
- return (out or b"") if proc.returncode == 0 else None
+ return (proc.stdout or b"") if proc.returncode == 0 else None
+
+
+async def _run(cmd: list[str], data: bytes | None) -> bytes | None:
+ # In a thread, not asyncio's subprocesses: on Windows the client runs a
+ # selector loop (aiortc's ICE needs one), which cannot start a process.
+ return await asyncio.to_thread(_run_blocking, cmd, data)
async def read_text() -> str | None: