@@ -11,27 +11,27 @@ def __init__(self, nbapp: NotebookApp):
11
11
self .config = nbapp .web_app .settings ["nbresuse_display_config" ]
12
12
self .nbapp = nbapp
13
13
14
+ def get_process_metric_value (self , process , name , kwargs , attribute = None ):
15
+ try :
16
+ # psutil.Process methods will either return...
17
+ metric_value = getattr (process , name )(** kwargs )
18
+ if attribute is not None : # ... a named tuple
19
+ return getattr (metric_value , attribute )
20
+ else : # ... or a number
21
+ return metric_value
22
+ # Avoid littering logs with stack traces
23
+ # complaining about dead processes
24
+ except BaseException :
25
+ return 0
26
+
14
27
def process_metric (self , name , kwargs = {}, attribute = None ):
15
28
if psutil is None :
16
29
return None
17
30
else :
18
31
current_process = psutil .Process ()
19
32
all_processes = [current_process ] + current_process .children (recursive = True )
20
33
21
- def get_process_metric (process , name , kwargs , attribute = None ):
22
- try :
23
- # psutil.Process methods will either return...
24
- metric_value = getattr (process , name )(** kwargs )
25
- if attribute is not None : # ... a named tuple
26
- return getattr (metric_value , attribute )
27
- else : # ... or a number
28
- return metric_value
29
- # Avoid littering logs with stack traces
30
- # complaining about dead processes
31
- except BaseException :
32
- return 0
33
-
34
- process_metric_value = lambda process : get_process_metric (
34
+ process_metric_value = lambda process : self .get_process_metric_value (
35
35
process , name , kwargs , attribute
36
36
)
37
37
0 commit comments