summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjonathan vanasco <jonathan@2xlp.com>2013-05-29 22:29:11 -0400
committerJames Socol <me@jamessocol.com>2013-05-30 11:22:28 -0400
commit9be7f5c4f2437f9aa7f4942eca241cb74ba81104 (patch)
tree6e53283c108a6cbcc04971d938124c4c19630aae
parentf28f6c988fc087388577cd5e8df28ca8d648c0e3 (diff)
downloadpystatsd-9be7f5c4f2437f9aa7f4942eca241cb74ba81104.tar.gz
Don't try to pop an empty pipeline. Fix #28.
-rw-r--r--statsd/client.py2
-rw-r--r--statsd/tests.py7
2 files changed, 9 insertions, 0 deletions
diff --git a/statsd/client.py b/statsd/client.py
index e88d23a..677c8f5 100644
--- a/statsd/client.py
+++ b/statsd/client.py
@@ -117,6 +117,8 @@ class Pipeline(StatsClient):
def send(self):
# Use pop(0) to preserve the order of the stats.
+ if not self._stats:
+ return
data = self._stats.pop(0)
while self._stats:
stat = self._stats.pop(0)
diff --git a/statsd/tests.py b/statsd/tests.py
index 59e8f24..7d9f73d 100644
--- a/statsd/tests.py
+++ b/statsd/tests.py
@@ -280,6 +280,13 @@ def test_pipeline():
_sock_check(sc, 1, 'foo:1|c\nbar:-1|c\nbaz:320|ms')
+def test_pipeline_null():
+ """Ensure we don't error on an empty pipeline."""
+ sc = _client()
+ pipe = sc.pipeline()
+ pipe.send()
+
+
def test_pipeline_manager():
sc = _client()
with sc.pipeline() as pipe: