Skip to content

Commit

Permalink
Fallback for destroyed processes
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyTsimfer committed Jul 22, 2024
1 parent 819668b commit 8aaca70
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 8aaca70

Please sign in to comment.