1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 00:08:11 +00:00

Catch exception when psutil returns OSError

This commit is contained in:
grossmj 2020-08-06 13:37:27 +09:30
parent 855a95de49
commit 6761ae3445

View File

@ -21,6 +21,9 @@ import psutil
from gns3server.utils.cpu_percent import CpuPercent
import logging
log = logging.getLogger(__name__)
class NotificationQueue(asyncio.Queue):
"""
@ -51,10 +54,14 @@ class NotificationQueue(asyncio.Queue):
"""
Return the content of the ping notification
"""
msg = {}
msg = {"cpu_usage_percent": 0,
"memory_usage_percent": 0}
# Non blocking call in order to get cpu usage. First call will return 0
msg["cpu_usage_percent"] = CpuPercent.get(interval=None)
msg["memory_usage_percent"] = psutil.virtual_memory().percent
try:
msg["cpu_usage_percent"] = CpuPercent.get(interval=None)
msg["memory_usage_percent"] = psutil.virtual_memory().percent
except OSError as e:
log.warning("Could not get CPU and memory usage from psutil: {}".format(e))
return msg
async def get_json(self, timeout):