Use 'with' context manager so we don't leak open files.

pull/966/head
Alessio Sergi 2016-11-12 13:00:12 +01:00
parent 846c9e843d
commit e4348e1cc2
1 changed files with 3 additions and 2 deletions

View File

@ -134,8 +134,9 @@ class GlancesProcesses(object):
# For the moment, only available on LINUX
# Waiting from https://github.com/giampaolo/psutil/issues/720
try:
return int(open('/proc/sys/kernel/pid_max').readline().rstrip())
except IOError:
with open('/proc/sys/kernel/pid_max', 'rb') as f:
return int(f.read())
except (OSError, IOError):
return None
@property