Skip to content

Commit e240d70

Browse files
committed
Fixed StdioServer.write to flush stdout buffer in a separate thread using anyio.to_thread.run_sync.
1 parent 47badae commit e240d70

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lf_toolkit/io/stdio_server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from typing import Optional
44

5+
import anyio
56
from anyio.streams.file import FileReadStream
67
from anyio.streams.file import FileWriteStream
78
from anyio.streams.stapled import StapledByteStream
@@ -25,7 +26,7 @@ async def read(self, size: int) -> bytes:
2526

2627
async def write(self, data: bytes):
2728
await self.stream.send(data)
28-
await self.stream.flush()
29+
await anyio.to_thread.run_sync(sys.stdout.buffer.flush)
2930

3031
async def close(self):
3132
await self.stream.aclose()

0 commit comments

Comments
 (0)