mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
python: Migrate open statements to use with.
This is low priority, but it's nice to be consistently using the best practice pattern. Fixes: #12419.
This commit is contained in:
@@ -18,7 +18,8 @@ def nagios_from_file(results_file: str, max_time_diff: int=60 * 2) -> 'Tuple[int
|
||||
This file is created by various nagios checking cron jobs such as
|
||||
check-rabbitmq-queues and check-rabbitmq-consumers"""
|
||||
|
||||
data = open(results_file).read().strip()
|
||||
with open(results_file, 'r') as f:
|
||||
data = f.read().strip()
|
||||
pieces = data.split('|')
|
||||
|
||||
if not len(pieces) == 4:
|
||||
|
||||
@@ -34,7 +34,8 @@ down_count = 0
|
||||
for results_file_name in os.listdir(RESULTS_DIR):
|
||||
this_state = "OK"
|
||||
results_file = os.path.join(RESULTS_DIR, results_file_name)
|
||||
data = open(results_file).read().strip()
|
||||
with open(results_file, 'r') as f:
|
||||
data = f.read().strip()
|
||||
last_check = os.stat(results_file).st_mtime
|
||||
time_since_last_check = time.time() - last_check
|
||||
# time_since_last_check threshold needs to be strictly greater
|
||||
|
||||
@@ -32,7 +32,8 @@ def report(state, data, last_check):
|
||||
data))
|
||||
exit(states[state])
|
||||
|
||||
data = open(RESULTS_FILE).read().strip()
|
||||
with open(RESULTS_FILE, 'r') as f:
|
||||
data = f.read().strip()
|
||||
if data.split("\n")[-1].strip() == "0":
|
||||
state = "OK"
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user