No need to do a shutdown(wait=True) when in a context-manager

It isn't needed to do this explicitly since the __exit__
method of a executor already does this automatically when
exiting the context that was entered.

See:

https://github.com/python/cpython/blob/master/Lib/\
                  concurrent/futures/_base.py#L580

So might as well save some space and just let the context
manager do its job.

Change-Id: I963d5e3c8a185716dd2bb37fa5cb3197c70bd2e1
This commit is contained in:
Joshua Harlow 2017-06-23 21:26:35 -07:00
parent 32e2d9c3c1
commit fabe867ba2
2 changed files with 32 additions and 38 deletions

View File

@ -35,27 +35,24 @@ class HealthManager(object):
amp_health_repo = repo.AmphoraHealthRepository()
with futures.ThreadPoolExecutor(max_workers=self.threads) as executor:
try:
# Don't start checking immediately, as the health manager may
# have been down for a while and amphorae not able to check in.
LOG.debug("Pausing before starting health check")
time.sleep(CONF.health_manager.heartbeat_timeout)
# Don't start checking immediately, as the health manager may
# have been down for a while and amphorae not able to check in.
LOG.debug("Pausing before starting health check")
time.sleep(CONF.health_manager.heartbeat_timeout)
while True:
session = db_api.get_session()
LOG.debug("Starting amphora health check")
failover_count = 0
while True:
session = db_api.get_session()
LOG.debug("Starting amphora health check")
failover_count = 0
while True:
amp = amp_health_repo.get_stale_amphora(session)
if amp is None:
break
failover_count += 1
LOG.info("Stale amphora's id is: %s",
amp.amphora_id)
executor.submit(self.cw.failover_amphora,
amp.amphora_id)
if failover_count > 0:
LOG.info("Failed over %s amphora",
failover_count)
time.sleep(CONF.health_manager.health_check_interval)
finally:
executor.shutdown(wait=True)
amp = amp_health_repo.get_stale_amphora(session)
if amp is None:
break
failover_count += 1
LOG.info("Stale amphora's id is: %s",
amp.amphora_id)
executor.submit(self.cw.failover_amphora,
amp.amphora_id)
if failover_count > 0:
LOG.info("Failed over %s amphora",
failover_count)
time.sleep(CONF.health_manager.health_check_interval)

View File

@ -110,18 +110,15 @@ class CertRotation(object):
amp_repo = repo.AmphoraRepository()
with futures.ThreadPoolExecutor(max_workers=self.threads) as executor:
try:
session = db_api.get_session()
rotation_count = 0
while True:
amp = amp_repo.get_cert_expiring_amphora(session)
if not amp:
break
rotation_count += 1
LOG.debug("Cert expired amphora's id is: %s", amp.id)
executor.submit(self.cw.amphora_cert_rotation, amp.id)
if rotation_count > 0:
LOG.info("Rotated certificates for %s amphora" %
rotation_count)
finally:
executor.shutdown(wait=True)
session = db_api.get_session()
rotation_count = 0
while True:
amp = amp_repo.get_cert_expiring_amphora(session)
if not amp:
break
rotation_count += 1
LOG.debug("Cert expired amphora's id is: %s", amp.id)
executor.submit(self.cw.amphora_cert_rotation, amp.id)
if rotation_count > 0:
LOG.info("Rotated certificates for %s amphora" %
rotation_count)