Skip to content

Commit 1949d18

Browse files
committed
Port voila-dashboards#969 to this PR
1 parent 2625cf5 commit 1949d18

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

voila/notebook_renderer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ async def _jinja_notebook_execute(self, nb, kernel_id):
214214
# (it seems to be local to our block)
215215
nb.cells = result.cells
216216

217+
await self._cleanup_resources()
218+
217219
async def _jinja_cell_generator(self, nb, kernel_id, timeout_callback):
218220
"""Generator that will execute a single notebook cell at a time"""
219221
nb, _ = ClearOutputPreprocessor().preprocess(
@@ -279,6 +281,12 @@ async def _jinja_cell_generator(self, nb, kernel_id, timeout_callback):
279281
finally:
280282
yield output_cell
281283

284+
await self._cleanup_resources()
285+
286+
async def _cleanup_resources(self):
287+
await ensure_async(self.executor.km.cleanup_resources())
288+
await ensure_async(self.executor.kc.stop_channels())
289+
282290
async def load_notebook(self, path):
283291

284292
model = await ensure_async(self.contents_manager.get(path=path))

voila/voila_kernel_manager.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ def fill_if_needed(
186186
default_config = self.kernel_pools_size.get('default', {})
187187
kernel_name = default_config.get('kernel', 'python3')
188188
kernel_size = default_config.get('pool_size', 1)
189-
self.log.info(f'Pre-heat {kernel_name} kernel for {notebook_name}')
190189
pool = self._pools.get(notebook_name, [])
191190
self._pools[notebook_name] = pool
192191
if 'path' not in kwargs:
@@ -201,14 +200,14 @@ def fill_if_needed(
201200
kernel_env[key] = self.kernel_env_variables[key]
202201
kwargs['env'] = kernel_env
203202

204-
unheated = kernel_size
203+
heated = len(pool)
205204

206205
def task_counter(tk):
207-
nonlocal unheated
208-
unheated -= 1
209-
if (unheated == 0):
206+
nonlocal heated
207+
heated += 1
208+
if (heated == kernel_size):
210209
self.log.info(
211-
'Pre-heated %s kernel(s) for notebook %s', kernel_size, notebook_name
210+
'Kernel pool of %s is filled with %s kernel(s)', notebook_name, kernel_size
212211
)
213212

214213
for _ in range(kernel_size - len(pool)):

0 commit comments

Comments
 (0)