Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve data read #362

Merged
merged 2 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading