|
14 | 14 |
|
15 | 15 | try: |
16 | 16 | import queue |
17 | | -except: |
| 17 | +except ImportError: |
18 | 18 | import Queue as queue |
19 | 19 |
|
20 | 20 |
|
@@ -48,17 +48,20 @@ def __init__(self, write_key=None, host=None, debug=False, |
48 | 48 | self.consumers = None |
49 | 49 | else: |
50 | 50 | # On program exit, allow the consumer thread to exit cleanly. |
51 | | - # This prevents exceptions and a messy shutdown when the interpreter is |
52 | | - # destroyed before the daemon thread finishes execution. However, it |
53 | | - # is *not* the same as flushing the queue! To guarantee all messages |
54 | | - # have been delivered, you'll still need to call flush(). |
| 51 | + # This prevents exceptions and a messy shutdown when the |
| 52 | + # interpreter is destroyed before the daemon thread finishes |
| 53 | + # execution. However, it is *not* the same as flushing the queue! |
| 54 | + # To guarantee all messages have been delivered, you'll still need |
| 55 | + # to call flush(). |
55 | 56 | if send: |
56 | 57 | atexit.register(self.join) |
57 | 58 | for n in range(thread): |
58 | 59 | self.consumers = [] |
59 | | - consumer = Consumer(self.queue, write_key, host=host, on_error=on_error, |
60 | | - flush_at=flush_at, flush_interval=flush_interval, |
61 | | - gzip=gzip, retries=max_retries, timeout=timeout) |
| 60 | + consumer = Consumer( |
| 61 | + self.queue, write_key, host=host, on_error=on_error, |
| 62 | + flush_at=flush_at, flush_interval=flush_interval, |
| 63 | + gzip=gzip, retries=max_retries, timeout=timeout, |
| 64 | + ) |
62 | 65 | self.consumers.append(consumer) |
63 | 66 |
|
64 | 67 | # if we've disabled sending, just don't start the consumer |
@@ -87,7 +90,8 @@ def identify(self, user_id=None, traits=None, context=None, timestamp=None, |
87 | 90 | return self._enqueue(msg) |
88 | 91 |
|
89 | 92 | def track(self, user_id=None, event=None, properties=None, context=None, |
90 | | - timestamp=None, anonymous_id=None, integrations=None, message_id=None): |
| 93 | + timestamp=None, anonymous_id=None, integrations=None, |
| 94 | + message_id=None): |
91 | 95 | properties = properties or {} |
92 | 96 | context = context or {} |
93 | 97 | integrations = integrations or {} |
@@ -129,7 +133,8 @@ def alias(self, previous_id=None, user_id=None, context=None, |
129 | 133 | return self._enqueue(msg) |
130 | 134 |
|
131 | 135 | def group(self, user_id=None, group_id=None, traits=None, context=None, |
132 | | - timestamp=None, anonymous_id=None, integrations=None, message_id=None): |
| 136 | + timestamp=None, anonymous_id=None, integrations=None, |
| 137 | + message_id=None): |
133 | 138 | traits = traits or {} |
134 | 139 | context = context or {} |
135 | 140 | integrations = integrations or {} |
@@ -266,7 +271,9 @@ def flush(self): |
266 | 271 | self.log.debug('successfully flushed about %s items.', size) |
267 | 272 |
|
268 | 273 | def join(self): |
269 | | - """Ends the consumer thread once the queue is empty. Blocks execution until finished""" |
| 274 | + """Ends the consumer thread once the queue is empty. |
| 275 | + Blocks execution until finished |
| 276 | + """ |
270 | 277 | for consumer in self.consumers: |
271 | 278 | consumer.pause() |
272 | 279 | try: |
|
0 commit comments