Skip to content

Commit

Permalink
Fallback for destroyed processes (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyTsimfer authored Jul 22, 2024
1 parent 33d1128 commit 2a9df7c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nbtools/nbstat/resource_entry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" ResourceEntry -- a dict-like class to hold all properties (Resources) of an entry. """
from datetime import datetime
import psutil

from .resource import Resource
from .utils import format_memory
Expand Down Expand Up @@ -75,7 +76,10 @@ def to_format_data(self, resource, terminal, **kwargs):
elif resource == Resource.CPU:
process = self[Resource.PROCESS]
if process is not None:
data = process.cpu_percent()
try:
data = process.cpu_percent()
except psutil.NoSuchProcess:
data = 0.0
data = round(data)

style = terminal.bold if data > 30 else ''
Expand Down

0 comments on commit 2a9df7c

Please sign in to comment.