代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/dnf 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From b7ab85d675417db3bc2eda499ee1844f8116d51e Mon Sep 17 00:00:00 2001
From: lingjuer <zhangchenglin@kylinos.cn>
Date: Fri, 28 Jul 2023 15:40:17 +0800
Subject: [PATCH] Add exception handling when reading files
---
dnf/cli/utils.py | 92 +++++++++++++++++++++++++-----------------------
1 file changed, 47 insertions(+), 45 deletions(-)
diff --git a/dnf/cli/utils.py b/dnf/cli/utils.py
index 1c3db75..2d3e352 100644
--- a/dnf/cli/utils.py
+++ b/dnf/cli/utils.py
@@ -59,51 +59,53 @@ def seconds_to_ui_time(seconds):
def get_process_info(pid):
"""Return info dict about a process."""
-
- pid = int(pid)
-
- # Maybe true if /proc isn't mounted, or not Linux ... or something.
- if (not os.path.exists("/proc/%d/status" % pid) or
- not os.path.exists("/proc/stat") or
- not os.path.exists("/proc/%d/stat" % pid)):
- return
-
- ps = {}
- with open("/proc/%d/status" % pid) as status_file:
- for line in status_file:
- if line[-1] != '\n':
- continue
- data = line[:-1].split(':\t', 1)
- if len(data) < 2:
- continue
- data[1] = dnf.util.rtrim(data[1], ' kB')
- ps[data[0].strip().lower()] = data[1].strip()
- if 'vmrss' not in ps:
- return
- if 'vmsize' not in ps:
- return
-
- boot_time = None
- with open("/proc/stat") as stat_file:
- for line in stat_file:
- if line.startswith("btime "):
- boot_time = int(line[len("btime "):-1])
- break
- if boot_time is None:
- return
-
- with open('/proc/%d/stat' % pid) as stat_file:
- ps_stat = stat_file.read().split()
- ps['start_time'] = boot_time + jiffies_to_seconds(ps_stat[21])
- ps['state'] = {'R' : _('Running'),
- 'S' : _('Sleeping'),
- 'D' : _('Uninterruptible'),
- 'Z' : _('Zombie'),
- 'T' : _('Traced/Stopped')
- }.get(ps_stat[2], _('Unknown'))
-
- return ps
-
+ try:
+ pid = int(pid)
+
+ # Maybe true if /proc isn't mounted, or not Linux ... or something.
+ if (not os.path.exists("/proc/%d/status" % pid) or
+ not os.path.exists("/proc/stat") or
+ not os.path.exists("/proc/%d/stat" % pid)):
+ return
+
+ ps = {}
+ with open("/proc/%d/status" % pid) as status_file:
+ for line in status_file:
+ if line[-1] != '\n':
+ continue
+ data = line[:-1].split(':\t', 1)
+ if len(data) < 2:
+ continue
+ data[1] = dnf.util.rtrim(data[1], ' kB')
+ ps[data[0].strip().lower()] = data[1].strip()
+ if 'vmrss' not in ps:
+ return
+ if 'vmsize' not in ps:
+ return
+
+ boot_time = None
+ with open("/proc/stat") as stat_file:
+ for line in stat_file:
+ if line.startswith("btime "):
+ boot_time = int(line[len("btime "):-1])
+ break
+ if boot_time is None:
+ return
+
+ with open('/proc/%d/stat' % pid) as stat_file:
+ ps_stat = stat_file.read().split()
+ ps['start_time'] = boot_time + jiffies_to_seconds(ps_stat[21])
+ ps['state'] = {'R' : _('Running'),
+ 'S' : _('Sleeping'),
+ 'D' : _('Uninterruptible'),
+ 'Z' : _('Zombie'),
+ 'T' : _('Traced/Stopped')
+ }.get(ps_stat[2], _('Unknown'))
+
+ return ps
+ except (OSError, ValueError) as e:
+ logger.error("Failed to get process info: %s", e)
+ return None
def show_lock_owner(pid):
"""Output information about process holding a lock."""
--
2.39.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。