Skip to content

Commit 47be1de

Browse files
committed
optimize stdio communication
1 parent 660f919 commit 47be1de

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

.vscode/launch.json

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,16 @@
8787
"module": "robotcode.debugger",
8888
"justMyCode": false,
8989
"args": [
90-
"-p", "6612",
90+
"-p",
91+
"6612",
9192
"-w",
9293
"--",
93-
"-d", "results",
94-
"-P", "./lib",
95-
"-P", "./resources",
94+
"-d",
95+
"results",
96+
"-P",
97+
"./lib",
98+
"-P",
99+
"./resources",
96100
//"C:\\tmp\\robottest\\tests\\bdd_style.robot"
97101
"."
98102
]
@@ -119,14 +123,7 @@
119123
"justMyCode": false,
120124
"args": [
121125
"--mode",
122-
"stdio",
123-
"--call-tracing",
124-
"--log-config",
125-
"log.ini"
126-
//"--debug",
127-
// "--debug-json-rpc",
128-
// "--debug-json-rpc-data",
129-
//"--debug-colored"
126+
"stdio"
130127
]
131128
},
132129
{
@@ -162,13 +159,17 @@
162159
"args": [
163160
"--mode",
164161
"stdio",
162+
"--log",
163+
"--log-level",
164+
"TRACE",
165165
"--call-tracing",
166-
"--log-config",
167-
"log.ini"
168-
//"--debug",
169-
// "--debug-json-rpc",
170-
// "--debug-json-rpc-data",
171-
//"--debug-colored"
166+
"--log-json-rpc",
167+
"--log-json-rpc-data",
168+
"--log-language-server",
169+
"--log-language-server-parts",
170+
"--log-robotframework",
171+
"--log-asyncio",
172+
"--debug-asyncio"
172173
]
173174
},
174175
{

robotcode/jsonrpc2/server.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,18 @@ def run_io_nonblocking() -> None:
183183

184184
async def aio_readline(rfile: BinaryIO, protocol: asyncio.Protocol) -> None:
185185
protocol.connection_made(transport)
186-
stdio_executor = ThreadPoolExecutor(max_workers=1, thread_name_prefix="aio_readline")
187-
with stdio_executor:
186+
187+
def run() -> None:
188188
while (
189189
self._stdio_stop_event is not None and not self._stdio_stop_event.is_set() and not rfile.closed
190190
):
191-
data = await self.loop.run_in_executor(
192-
stdio_executor, cast(io.BufferedReader, rfile).read1, 1000
193-
)
194-
protocol.data_received(data)
191+
if cast(io.BufferedReader, rfile).peek(1):
192+
data = cast(io.BufferedReader, rfile).read1(10000)
193+
194+
self.loop.call_soon_threadsafe(protocol.data_received, data)
195+
196+
with ThreadPoolExecutor(max_workers=1, thread_name_prefix="aio_readline") as stdio_executor:
197+
await asyncio.wrap_future(stdio_executor.submit(run))
195198

196199
self.loop.run_until_complete(aio_readline(transport.rfile, protocol))
197200

0 commit comments

Comments
 (0)