diff --git a/plugins/terminals/fps_terminals/win_server.py b/plugins/terminals/fps_terminals/win_server.py index f54f7f66..f1865391 100644 --- a/plugins/terminals/fps_terminals/win_server.py +++ b/plugins/terminals/fps_terminals/win_server.py @@ -1,6 +1,8 @@ import asyncio import os +from functools import partial +from anyio import to_thread from winpty import PTY # type: ignore from jupyverse_api.terminals import TerminalServer @@ -32,12 +34,10 @@ async def serve(self, websocket): async def send_data(self): while True: try: - data = self.process.read(blocking=False) + data = await to_thread.run_sync(partial(self.process.read, blocking=True)) except Exception: await self.websocket.send_json(["disconnect", 1]) return - if not data: - await asyncio.sleep(0.1) else: for websocket in self.websockets: await websocket.send_json(["stdout", data]) diff --git a/plugins/terminals/pyproject.toml b/plugins/terminals/pyproject.toml index 2273d1b8..58b3481a 100644 --- a/plugins/terminals/pyproject.toml +++ b/plugins/terminals/pyproject.toml @@ -11,6 +11,7 @@ dependencies = [ "websockets", "pywinpty;platform_system=='Windows'", "jupyverse-api >=0.1.2,<1", + "anyio >=4,<5", ] dynamic = ["version"] [[project.authors]]