Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion segment/analytics/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def __init__(
# to call flush().
if send:
atexit.register(self.join)
self.consumers = []
for _ in range(thread):
self.consumers = []
consumer = Consumer(
self.queue,
write_key,
Expand Down
11 changes: 11 additions & 0 deletions segment/analytics/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ def test_shutdown(self):
for consumer in client.consumers:
self.assertFalse(consumer.is_alive())

def test_thread_option_keeps_every_consumer(self):
client = Client("testsecret", thread=3, on_error=self.fail)
try:
self.assertEqual(len(client.consumers), 3)
self.assertTrue(all(consumer.is_alive() for consumer in client.consumers))
finally:
client.shutdown()
# shutdown() has to stop every consumer thread, not only the last one
for consumer in client.consumers:
self.assertFalse(consumer.is_alive())

def test_synchronous(self):
client = Client("testsecret", sync_mode=True)

Expand Down