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 30, 2023
1 parent 3125077 commit 6808046
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions instana/collector/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,11 @@ def prepare_and_report_data(self):
Prepare and report the data payload.
@return: Boolean
"""
if env_is_test is False:
lock_acquired = self.background_report_lock.acquire(False)
if lock_acquired:
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")
if env_is_test:
return True
with self.background_report_lock:
payload = self.prepare_payload()
self.agent.report_data_payload(payload)
return True

def prepare_payload(self):
Expand Down

0 comments on commit 6808046

Please sign in to comment.