Skip to content
Merged
Changes from 1 commit
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
11 changes: 7 additions & 4 deletions python/copilot/jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,23 @@ async def stop(self):
self._stderr_thread.join(timeout=1.0)

async def request(
self, method: str, params: Optional[dict] = None, timeout: float = 30.0
self, method: str, params: Optional[dict] = None, timeout: Optional[float] = None
) -> Any:
"""
Send a JSON-RPC request and wait for response

Args:
method: Method name
params: Optional parameters
timeout: Request timeout in seconds (default 30s)
timeout: Optional request timeout in seconds. If None (default),
waits indefinitely for the server to respond.

Returns:
The result from the response

Raises:
JsonRpcError: If server returns an error
asyncio.TimeoutError: If request times out
asyncio.TimeoutError: If request times out (only when timeout is set)
"""
request_id = str(uuid.uuid4())

Expand All @@ -141,7 +142,9 @@ async def request(
await self._send_message(message)

try:
return await asyncio.wait_for(future, timeout=timeout)
if timeout is not None:
return await asyncio.wait_for(future, timeout=timeout)
return await future
finally:
with self._pending_lock:
self.pending_requests.pop(request_id, None)
Expand Down
Loading