Use context managers as suggested by PyLint 2.8.2
PyLint 2.8.2 reports the following suggestions for two Python scripts
used in the system test suite:
************* Module tests_rndc_deadlock
bin/tests/system/addzone/tests_rndc_deadlock.py:71:4: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
************* Module tests-shutdown
bin/tests/system/shutdown/tests-shutdown.py:68:4: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
bin/tests/system/shutdown/tests-shutdown.py:154:8: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
Implement the above suggestions by using
concurrent.futures.ThreadPoolExecutor() and subprocess.Popen() as
context managers.
This commit is contained in:
@@ -68,23 +68,22 @@ def test_rndc_deadlock():
|
||||
test_state = {'finished': False}
|
||||
|
||||
# Create 4 worker threads running "rndc" commands in a loop.
|
||||
executor = concurrent.futures.ThreadPoolExecutor()
|
||||
for i in range(1, 5):
|
||||
domain = 'example%d' % i
|
||||
executor.submit(rndc_loop, test_state, domain)
|
||||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||
for i in range(1, 5):
|
||||
domain = 'example%d' % i
|
||||
executor.submit(rndc_loop, test_state, domain)
|
||||
|
||||
# Run "rndc status" in 1-second intervals for a maximum of 10 seconds. If
|
||||
# any "rndc status" command fails, the loop will be interrupted.
|
||||
server_is_responsive = True
|
||||
attempts = 10
|
||||
while server_is_responsive and attempts > 0:
|
||||
server_is_responsive = check_if_server_is_responsive()
|
||||
attempts -= 1
|
||||
time.sleep(1)
|
||||
# Run "rndc status" in 1-second intervals for a maximum of 10 seconds.
|
||||
# If any "rndc status" command fails, the loop will be interrupted.
|
||||
server_is_responsive = True
|
||||
attempts = 10
|
||||
while server_is_responsive and attempts > 0:
|
||||
server_is_responsive = check_if_server_is_responsive()
|
||||
attempts -= 1
|
||||
time.sleep(1)
|
||||
|
||||
# Signal worker threads that the test is finished.
|
||||
test_state['finished'] = True
|
||||
executor.shutdown()
|
||||
# Signal worker threads that the test is finished.
|
||||
test_state['finished'] = True
|
||||
|
||||
# Check whether all "rndc status" commands succeeded.
|
||||
assert server_is_responsive
|
||||
|
||||
Reference in New Issue
Block a user