def _create_users(org_id, users_data, remote_addr, background): global _users_background org = organization.get_by_id(org_id) users = [] hosts_online = host.get_hosts_online() if background: user_queue = callqueue.CallQueue(maxsize=hosts_online) user_queue.start(hosts_online) _users_background_lock.acquire() if _users_background: return _users_background = True _users_background_lock.release() try: if background: for i, user_data in enumerate(users_data): user_queue.put(_create_user, users, org, user_data, remote_addr, False) else: for i, user_data in enumerate(users_data): err = _create_user(users, org, user_data, remote_addr, True) if err: return err except: logger.exception('Error creating users', 'users') raise finally: if background: user_queue.close() _users_background_lock.acquire() _users_background = False _users_background_lock.release() event.Event(type=ORGS_UPDATED) event.Event(type=USERS_UPDATED, resource_id=org.id) event.Event(type=SERVERS_UPDATED) if len(users) == 1: logger.LogEntry(message='Created new user.') else: logger.LogEntry(message='Created %s new users.' % len(users)) return utils.jsonify(users)