Skip to content

Commit

Permalink
Refactored TelemetrySender.send function
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarevevgeny committed Mar 18, 2021
1 parent a330e91 commit ac20ea6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions model-optimizer/telemetry/utils/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def _future_callback(future):
with self._lock:
self.queue_size -= 1

callback_needed = False
fut = None
with self._lock:
if self.queue_size < MAX_QUEUE_SIZE:
fut = self.executor.submit(backend.send, message)

This comment has been minimized.

Copy link
@nosovmik

nosovmik Mar 18, 2021

Contributor

I asked about moving 'future' creation outside of lock just because it is good practice to hold a lock for a very minimum time and only when it is needed. Here it is needed only to check and increase queue size

callback_needed = True
self.queue_size += 1
else:
pass # dropping a message because the queue is full
if callback_needed:
# to avoid dead lock we should not add callback inside the "with self._lock" block
if fut is not None:
fut.add_done_callback(_future_callback)

def force_shutdown(self, timeout: float):
Expand Down

0 comments on commit ac20ea6

Please sign in to comment.