From b02a43291cc5e2d5677ecbb80c0fd608d67a1374 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 27 Nov 2018 12:59:04 +1100 Subject: [PATCH] Handle disappearing pids in mlock_report.py If a pid disappears on us while we're reading, we should just continue on. EnvironmentError is just an alias for OSError since Python 3.3, so use the latter name. [0] [0] https://docs.python.org/3/library/exceptions.html#OSError Change-Id: I3a25cca328e1469f72c84a118a9691c1c0258bc4 Closes-Bug: #1926434 --- tools/mlock_report.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tools/mlock_report.py b/tools/mlock_report.py index b15a0bf80b..1b081bbe6f 100644 --- a/tools/mlock_report.py +++ b/tools/mlock_report.py @@ -24,17 +24,19 @@ def _get_report(): # iterate over the /proc/%pid/status files manually try: s = open("%s/%d/status" % (psutil.PROCFS_PATH, proc.pid), 'r') - except EnvironmentError: + with s: + for line in s: + result = LCK_SUMMARY_REGEX.search(line) + if result: + locked = int(result.group('locked')) + if locked: + mlock_users.append({'name': proc.name(), + 'pid': proc.pid, + 'locked': locked}) + except OSError: + # pids can disappear, we're ok with that continue - with s: - for line in s: - result = LCK_SUMMARY_REGEX.search(line) - if result: - locked = int(result.group('locked')) - if locked: - mlock_users.append({'name': proc.name(), - 'pid': proc.pid, - 'locked': locked}) + # produce a single line log message with per process mlock stats if mlock_users: