summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Socol <me@jamessocol.com>2020-10-08 07:45:09 -0400
committerGitHub <noreply@github.com>2020-10-08 07:45:09 -0400
commit9d9d9ef211f2c6e911cf325562fd8d35af5157cf (patch)
treee671566762b1bdce60a71c7db53d029d6b6f1cc1
parent1c90b9fdf322680e2625da659abc2aa5d79b5bff (diff)
parente7a36f9d68c44476184261371276c76bf7f22ff8 (diff)
downloadpystatsd-9d9d9ef211f2c6e911cf325562fd8d35af5157cf.tar.gz
Merge pull request #140 from jsocol/pr/136
Add `close()` method to UDP client
-rw-r--r--docs/reference.rst4
-rw-r--r--statsd/client/base.py4
-rw-r--r--statsd/client/udp.py5
3 files changed, 13 insertions, 0 deletions
diff --git a/docs/reference.rst b/docs/reference.rst
index de9b054..df691d8 100644
--- a/docs/reference.rst
+++ b/docs/reference.rst
@@ -28,6 +28,10 @@ server supports.
generally considered safe for the public internet, but private networks
may support larger packet sizes.
+.. py:method:: StatsClient.close()
+
+ Close the underlying UDP socket.
+
.. py:method:: StatsClient.incr(stat, count=1, rate=1)
Increment a :ref:`counter <counter-type>`.
diff --git a/statsd/client/base.py b/statsd/client/base.py
index 08474c6..e273b41 100644
--- a/statsd/client/base.py
+++ b/statsd/client/base.py
@@ -10,6 +10,10 @@ from .timer import Timer
class StatsClientBase(object):
"""A Base class for various statsd clients."""
+ def close(self):
+ """Used to close and clean up any underlying resources."""
+ raise NotImplementedError()
+
def _send(self):
raise NotImplementedError()
diff --git a/statsd/client/udp.py b/statsd/client/udp.py
index 790c5e8..ddb9d22 100644
--- a/statsd/client/udp.py
+++ b/statsd/client/udp.py
@@ -46,5 +46,10 @@ class StatsClient(StatsClientBase):
# No time for love, Dr. Jones!
pass
+ def close(self):
+ if self._sock and hasattr(self._sock, 'close'):
+ self._sock.close()
+ self._sock = None
+
def pipeline(self):
return Pipeline(self)