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 2bc0ee5
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,4 +1,5 @@
""" ResourceEntry -- a dict-like class to hold all properties (Resources) of an entry. """
import psutil
from datetime import datetime

from .resource import Resource
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 2bc0ee5

Please sign in to comment.