Skip to content

Commit

Permalink
Improve data read (#362)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
davidbrochart and pre-commit-ci[bot] authored Oct 29, 2023
1 parent 587074a commit db6bff4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions plugins/terminals/fps_terminals/win_server.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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])
Expand Down
1 change: 1 addition & 0 deletions plugins/terminals/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies = [
"websockets",
"pywinpty;platform_system=='Windows'",
"jupyverse-api >=0.1.2,<1",
"anyio >=4,<5",
]
dynamic = ["version"]
[[project.authors]]
Expand Down

0 comments on commit db6bff4

Please sign in to comment.