1313from .resource import Resource
1414from .resource_table import ResourceTable
1515from .utils import format_memory , pid_to_name , pid_to_ngid , true_len , true_rjust , true_center , FiniteList
16+ from ..run_notebook import get_run_notebook_name
1617
1718
1819
1920KERNEL_ID_SEARCHER = re .compile ('kernel-(.*).json' ).search
2021VSCODE_KEY_SEARCHER = re .compile ('key=b"(.*)"' ).search
2122SCRIPT_NAME_SEARCHER = re .compile ('python.* (.*).py' ).search
23+ RUN_NOTEBOOK_PATH_SEARCHER = re .compile ('/tmp/.*.json.*--HistoryManager.hist_file=:memory:.*' ).search
2224
2325
2426class ResourceInspector :
@@ -232,6 +234,7 @@ def get_process_table(self, formatter=None):
232234 kernel_id = KERNEL_ID_SEARCHER (cmdline )
233235 vscode_key = VSCODE_KEY_SEARCHER (cmdline )
234236 script_name = SCRIPT_NAME_SEARCHER (cmdline )
237+ run_notebook_path = RUN_NOTEBOOK_PATH_SEARCHER (cmdline )
235238
236239 if kernel_id :
237240 # The name will be changed by data from `notebook_table`.
@@ -245,6 +248,11 @@ def get_process_table(self, formatter=None):
245248 type_ = 'vscode'
246249 name = vscode_key .group (1 ).split ('-' )[0 ] + '.ipynb'
247250 path = kernel_id = vscode_key .group (1 )
251+ elif run_notebook_path :
252+ type_ = 'run_notebook'
253+ name = get_run_notebook_name (process .ppid ())
254+ path = cwd
255+ kernel_id = None
248256 elif script_name :
249257 type_ = 'script'
250258 name = script_name .group (1 ) + '.py'
@@ -258,7 +266,10 @@ def get_process_table(self, formatter=None):
258266
259267 # PYTHON_PPID = PPID if parent is Python process else -1
260268 ppid = process .ppid ()
261- if ppid in python_pids :
269+ if type_ == 'run_notebook' :
270+ # Spawned by `run_notebook` function of the library
271+ python_ppid = ppid
272+ elif ppid in python_pids :
262273 # Spawned by one of other Python processes
263274 type_ = 'subprocess'
264275 python_ppid = ppid
@@ -495,6 +506,12 @@ def get_view(self, name='nbstat', formatter=None, index_condition=None, force_st
495506 else :
496507 raise ValueError ('Wrong name of view to get!' )
497508
509+ # Filter some processes
510+ if 'nb' in name and table :
511+ bad_names = ['lsp_server' ]
512+ function = lambda index_value , _ : not any (name in index_value for name in bad_names )
513+ table .filter_on_index (function , inplace = True )
514+
498515 # Filter index of the table by a regular expression
499516 if table and index_condition is not None :
500517 function = lambda index_value , _ : bool (re .search (index_condition , str (index_value )))
0 commit comments