@@ -11,27 +11,27 @@ def __init__(self, nbapp: NotebookApp):
1111 self .config = nbapp .web_app .settings ["nbresuse_display_config" ]
1212 self .nbapp = nbapp
1313
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+
1427 def process_metric (self , name , kwargs = {}, attribute = None ):
1528 if psutil is None :
1629 return None
1730 else :
1831 current_process = psutil .Process ()
1932 all_processes = [current_process ] + current_process .children (recursive = True )
2033
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 (
3535 process , name , kwargs , attribute
3636 )
3737
0 commit comments