Skip to content

Commit db6bff4

Browse files
Improve data read (#362)
* Improve data read * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 587074a commit db6bff4

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

plugins/terminals/fps_terminals/win_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import asyncio
22
import os
3+
from functools import partial
34

5+
from anyio import to_thread
46
from winpty import PTY # type: ignore
57

68
from jupyverse_api.terminals import TerminalServer
@@ -32,12 +34,10 @@ async def serve(self, websocket):
3234
async def send_data(self):
3335
while True:
3436
try:
35-
data = self.process.read(blocking=False)
37+
data = await to_thread.run_sync(partial(self.process.read, blocking=True))
3638
except Exception:
3739
await self.websocket.send_json(["disconnect", 1])
3840
return
39-
if not data:
40-
await asyncio.sleep(0.1)
4141
else:
4242
for websocket in self.websockets:
4343
await websocket.send_json(["stdout", data])

plugins/terminals/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies = [
1111
"websockets",
1212
"pywinpty;platform_system=='Windows'",
1313
"jupyverse-api >=0.1.2,<1",
14+
"anyio >=4,<5",
1415
]
1516
dynamic = ["version"]
1617
[[project.authors]]

0 commit comments

Comments
 (0)