Skip to content

Commit 2c204df

Browse files
author
Ilya Volodarsky
committed
adding send flag to client
1 parent 532325a commit 2c204df

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

analytics/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
VERSION = '0.3.4'
2+
VERSION = '0.3.5'
33

44
import sys
55

analytics/client.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def __init__(self, secret=None,
105105
flush_at=20, flush_after=datetime.timedelta(0, 10),
106106
async=True, max_queue_size=10000,
107107
stats=Statistics(),
108-
timeout=10):
108+
timeout=10,
109+
send=True):
109110
"""Create a new instance of a analytics-python Client
110111
111112
:param str secret: The Segment.io API secret
@@ -121,7 +122,7 @@ def __init__(self, secret=None,
121122
thread, therefore not blocking code (this is the default). False to
122123
enable blocking and making the request on the calling thread.
123124
: param float timeout: Number of seconds before timing out request to Segment.io
124-
125+
: param bool send: True to send requests, False to not send. False to turn analytics off (for testing).
125126
"""
126127

127128
self.secret = secret
@@ -151,6 +152,8 @@ def __init__(self, secret=None,
151152
self.flush_lock = threading.Lock()
152153
self.flushing_thread = None
153154

155+
self.send = send
156+
154157
self.success_callbacks = []
155158
self.failure_callbacks = []
156159

@@ -317,6 +320,10 @@ def _should_flush(self):
317320

318321
def _enqueue(self, action):
319322

323+
# if we've disabled sending, just return False
324+
if not self.send:
325+
return False
326+
320327
submitted = False
321328

322329
if len(self.queue) < self.max_queue_size:

0 commit comments

Comments
 (0)