Skip to content

Commit 341f810

Browse files
committed
Remove extraneous cancel scope in Session
1 parent 8444ec6 commit 341f810

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

python_packages/jupyter_lsp/jupyter_lsp/session.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,23 @@ def stop(self):
128128
self.main_loop = None
129129

130130
async def run(self):
131-
"""run this session in a cancel scope and clean everything up on cancellation
132-
133-
the event `self.started` will be set when everything is set up and the session
134-
will be ready for communication
135-
"""
131+
"""run this session in a task group and clean everything up on cancellation"""
136132
self.thread_loop = IOLoop.current()
137-
async with CancelScope() as scope:
138-
self.cancelscope = scope
139-
await self.initialize()
140-
self.started.set()
141-
await self.listen()
142-
await self.cleanup()
143-
self.cancelscope = None
144-
self.thread_loop = None
133+
134+
try:
135+
async with anyio.create_task_group() as tg:
136+
self.cancelscope = tg.cancel_scope
137+
await self.initialize()
138+
self.started.set()
139+
tg.start_soon(self._read_lsp)
140+
tg.start_soon(self._write_lsp)
141+
tg.start_soon(self._broadcast_from_lsp)
142+
except Exception as e: # pragma: no cover
143+
self.log.exception("Execption while listening {}", e)
144+
finally:
145+
await self.cleanup()
146+
self.cancelscope = None
147+
self.thread_loop = None
145148

146149
async def initialize(self):
147150
"""initialize a language server session"""
@@ -154,16 +157,6 @@ async def initialize(self):
154157

155158
self.status = SessionStatus.STARTED
156159

157-
async def listen(self):
158-
"""start the actual read/write tasks"""
159-
try:
160-
async with anyio.create_task_group() as tg:
161-
await tg.spawn(self._read_lsp)
162-
await tg.spawn(self._write_lsp)
163-
await tg.spawn(self._broadcast_from_lsp)
164-
except Exception as e: # pragma: no cover
165-
self.log.exception("Execption while listening {}", e)
166-
167160
async def cleanup(self):
168161
"""clean up all of the state of the session"""
169162
self.status = SessionStatus.STOPPING

0 commit comments

Comments
 (0)