Merge ~hloeung/content-cache-charm:cleanup into content-cache-charm:master

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 1808dd1c7e0a4cdcf06fb6da129d0d02c61611c0
Merged at revision: f4fdacfb23cffcb850bf3961a98f84c2f5c8b3af
Proposed branch: ~hloeung/content-cache-charm:cleanup
Merge into: content-cache-charm:master
Diff against target: 32 lines (+6/-7)
1 file modified
lib/utils.py (+6/-7)
Reviewer Review Type Date Requested Status
Joel Sing (community) +1 Approve
Canonical IS Reviewers Pending
Review via email: mp+381421@code.launchpad.net

Commit message

Fixed based on review, compile the regex once

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Joel Sing (jsing) wrote :

LGTM

review: Approve (+1)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision f4fdacfb23cffcb850bf3961a98f84c2f5c8b3af

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/utils.py b/lib/utils.py
2index 577d9e9..25e5530 100644
3--- a/lib/utils.py
4+++ b/lib/utils.py
5@@ -176,22 +176,21 @@ LIMITS_MATCH = {
6
7
8 def process_rlimits(pid, res, limits_file=None):
9- if limits_file:
10- limitsf = limits_file
11- else:
12- limitsf = os.path.join('/proc', str(pid), 'limits')
13+ if not limits_file:
14+ limits_file = os.path.join('/proc', str(pid), 'limits')
15
16- if not os.path.exists(limitsf):
17+ if not os.path.exists(limits_file):
18 return None
19
20- with open(limitsf, 'r', encoding='utf-8') as f:
21+ with open(limits_file, 'r', encoding='utf-8') as f:
22 limits = f.read()
23
24 if res not in LIMITS_MATCH:
25 return None
26
27+ r = re.compile(r'^{}\s+\S+\s+(\S+)'.format(LIMITS_MATCH[res]))
28 for line in limits.split('\n'):
29- m = re.match(r'^{}\s+\S+\s+(\S+)'.format(LIMITS_MATCH[res]), line)
30+ m = r.match(line)
31 if m:
32 return m.group(1)
33

Subscribers

People subscribed via source and target branches