Skip to content

Commit 27099ca

Browse files
committed
Fix spawning the server
1 parent 655ace4 commit 27099ca

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pylsp/python_lsp.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def start_ws_lang_server(port, check_parent_process, handler_class) -> None:
117117
) from e
118118

119119
with ThreadPoolExecutor(max_workers=10) as tpool:
120-
send_queue = asyncio.Queue()
120+
send_queue = None
121+
loop = None
121122

122123
async def pylsp_ws(websocket):
123124
log.debug("Creating LSP object")
@@ -147,11 +148,15 @@ def send_message(message, websocket):
147148
"""Handler to send responses of processed requests to respective web socket clients"""
148149
try:
149150
payload = json.dumps(message, ensure_ascii=False)
150-
asyncio.run(send_queue.put((payload, websocket)))
151+
loop.call_soon_threadsafe(send_queue.put_nowait, (payload, websocket))
151152
except Exception as e:
152153
log.exception("Failed to write message %s, %s", message, str(e))
153154

154155
async def run_server():
156+
nonlocal send_queue, loop
157+
send_queue = asyncio.Queue()
158+
loop = asyncio.get_running_loop()
159+
155160
async with websockets.serve(pylsp_ws, port=port):
156161
while 1:
157162
# Wait until payload is available for sending

0 commit comments

Comments
 (0)