[Kimchi-devel] [kimchi-devel][PATCH 2/7] Fix file handler leak for uptime file
Aline Manera
alinefm at linux.vnet.ibm.com
Thu Jan 22 17:40:44 UTC 2015
Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>
On 20/01/2015 06:45, lvroyce at linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
>
> Proc uptime file opened without close,
> close it in with clause.
>
> Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
> ---
> src/kimchi/model/host.py | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/kimchi/model/host.py b/src/kimchi/model/host.py
> index dff89cb..7f2ccdc 100644
> --- a/src/kimchi/model/host.py
> +++ b/src/kimchi/model/host.py
> @@ -167,8 +167,9 @@ class HostStatsModel(object):
> # FIXME when we upgrade psutil, we can get uptime by psutil.uptime
> # we get uptime by float(open("/proc/uptime").readline().split()[0])
> # and calculate the first io_rate after the OS started.
> - seconds = (timestamp - preTimeStamp if preTimeStamp else
> - float(open("/proc/uptime").readline().split()[0]))
> + with open("/proc/uptime") as time_f:
> + seconds = (timestamp - preTimeStamp if preTimeStamp else
> + float(time_f.readline().split()[0]))
>
> self.host_stats['timestamp'] = timestamp
> self._get_host_disk_io_rate(seconds)
More information about the Kimchi-devel
mailing list