@@ -105,7 +105,8 @@ def __init__(self, secret=None,
105
105
flush_at = 20 , flush_after = datetime .timedelta (0 , 10 ),
106
106
async = True , max_queue_size = 10000 ,
107
107
stats = Statistics (),
108
- timeout = 10 ):
108
+ timeout = 10 ,
109
+ send = True ):
109
110
"""Create a new instance of a analytics-python Client
110
111
111
112
:param str secret: The Segment.io API secret
@@ -121,7 +122,7 @@ def __init__(self, secret=None,
121
122
thread, therefore not blocking code (this is the default). False to
122
123
enable blocking and making the request on the calling thread.
123
124
: 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).
125
126
"""
126
127
127
128
self .secret = secret
@@ -151,6 +152,8 @@ def __init__(self, secret=None,
151
152
self .flush_lock = threading .Lock ()
152
153
self .flushing_thread = None
153
154
155
+ self .send = send
156
+
154
157
self .success_callbacks = []
155
158
self .failure_callbacks = []
156
159
@@ -317,6 +320,10 @@ def _should_flush(self):
317
320
318
321
def _enqueue (self , action ):
319
322
323
+ # if we've disabled sending, just return False
324
+ if not self .send :
325
+ return False
326
+
320
327
submitted = False
321
328
322
329
if len (self .queue ) < self .max_queue_size :
0 commit comments