Skip to content

Commit

Permalink
move changes to base.py to next PR
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewqian2001datadog committed Jul 16, 2024
1 parent 2ce4ebf commit 4739c37
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions datadog/dogstatsd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def __init__(
self._flush_interval = flush_interval
self._flush_thread_stop = threading.Event()
self._flush_thread = None
self._start_flush_thread(self._flush_interval, self.flush)
self._start_flush_thread(self._flush_interval)

self._queue = None
self._sender_thread = None
Expand Down Expand Up @@ -514,7 +514,7 @@ def enable_telemetry(self):
self._telemetry = True

# Note: Invocations of this method should be thread-safe
def _start_flush_thread(self, flush_interval, flush_function):
def _start_flush_thread(self, flush_interval):
if self._disable_buffering or self._flush_interval <= MIN_FLUSH_INTERVAL:
log.debug("Statsd periodic buffer flush is disabled")
return
Expand All @@ -528,7 +528,7 @@ def _start_flush_thread(self, flush_interval, flush_function):
def _flush_thread_loop(self, flush_interval):
while not self._flush_thread_stop.is_set():
time.sleep(flush_interval)
flush_function()
self.flush()

self._flush_thread = threading.Thread(
name="{}_flush_thread".format(self.__class__.__name__),
Expand All @@ -544,12 +544,12 @@ def _flush_thread_loop(self, flush_interval):
)

# Note: Invocations of this method should be thread-safe
def _stop_flush_thread(self, flush_function):
def _stop_flush_thread(self):
if not self._flush_thread:
return

try:
flush_function()
self.flush()
finally:
pass

Expand Down Expand Up @@ -590,11 +590,11 @@ def disable_buffering(self, is_disabled):
# otherwise start up the flushing thread and enable the buffering.
if is_disabled:
self._send = self._send_to_server
self._stop_flush_thread(self.flush)
self._stop_flush_thread()
log.debug("Statsd buffering is disabled")
else:
self._send = self._send_to_buffer
self._start_flush_thread(self._flush_interval, self.flush)
self._start_flush_thread(self._flush_interval)

@staticmethod
def resolve_host(host, use_default_route):
Expand Down Expand Up @@ -1408,7 +1408,7 @@ def pre_fork(self):
self._forking = True

with self._config_lock:
self._stop_flush_thread(self.flush)
self._stop_flush_thread()
self._stop_sender_thread()
self.close_socket()

Expand All @@ -1422,7 +1422,7 @@ def post_fork(self):
self._forking = False

with self._config_lock:
self._start_flush_thread(self._flush_interval, self.flush)
self._start_flush_thread(self._flush_interval)
self._start_sender_thread()

def stop(self):
Expand Down

0 comments on commit 4739c37

Please sign in to comment.