Skip to content

Commit

Permalink
refactor: Using context manager to handle threading.Lock
Browse files Browse the repository at this point in the history
Signed-off-by: Paulo Vital <[email protected]>
  • Loading branch information
pvital committed Nov 28, 2023
1 parent 3125077 commit e35d652
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions instana/collector/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit e35d652

Please sign in to comment.