s.set_auth_method(BasicAuthentication(opts.username, opts.password))
    server.set_active_server(s)

    if opts.randomize:
        print """
        ====================================================
        You have opted to allow the program to randomly 
        select a subscription from all available.  This 
        can increase run time as the application will 
        have to work harder to find a suitable subscription.
        ====================================================
        """
    try:
        envid = process_environment(opts.org, opts.env)
        pool_ids = get_pool_ids(opts.org)
    except Exception, e:
        sys.stderr.write("Error: An exception occurred %s" % e)

    manager = Manager()
    maxconnections = 4
    sem = manager.BoundedSemaphore(maxconnections)
    pool = Pool(processes=maxconnections * 2)

    for i in range(int(opts.maxsystems)):
        if opts.debug:
            print 'Starting thread: [%s] for loadig systems' % i
        pool.apply_async(create_subscribed_systems,
                         args=(opts.org, envid, pool_ids, opts.randomize, sem))
    pool.close()
    pool.join()
Example #2
0
from multiprocessing import Manager

manager = Manager()

sem = manager.BoundedSemaphore(3)

sem.acquire()

# ... access limited resource ...

sem.release()