diff --git a/instana/collector/base.py b/instana/collector/base.py index ba2c73c3f..818e45d28 100644 --- a/instana/collector/base.py +++ b/instana/collector/base.py @@ -151,15 +151,12 @@ def prepare_and_report_data(self): @return: Boolean """ if env_is_test is False: - lock_acquired = self.background_report_lock.acquire(False) - if lock_acquired: + with self.background_report_lock: try: payload = self.prepare_payload() self.agent.report_data_payload(payload) - finally: - self.background_report_lock.release() - else: - logger.debug("prepare_and_report_data: Couldn't acquire lock") + except: + logger.debug("prepare_and_report_data: Couldn't acquire lock") return True def prepare_payload(self):