#!/usr/bin/python
#
from univention.lib.umc import Client
import threading
import time
import random
import sys

if __name__ == '__main__':
	client = Client()

	running_threads = []

	def try_auth():
		client.authenticate('Administrator', 'univention')
		print ' .',
		sys.stdout.flush()

	for i in xrange(500):
		thread = threading.Thread(target=try_auth)
		running_threads.append(thread)
		thread.start()
		time.sleep(random.random()*0.2)

	remaining = 1
	while remaining:
		running_threads = [x for x in running_threads if x.is_alive()]
		remaining = len(running_threads)
		print '%d remaining' % (remaining,)
		if not remaining:
			break
		time.sleep(1)
