Example #1
0
def test_pool2():
    stuff = D._aliases['pydotest'].copy()
    D.initAlias(
        'pydotestpool',
        stuff['driver'],
        stuff['connectArgs'],
        # keep_poolsize actually doesn't matter here
        D.ConnectionPool(max_poolsize=0, keep_poolsize=4),
        stuff['verbose'])
    hold = True
    threads = []

    class mythread(threading.Thread):
        def run(self):
            mydb = D.getConnection('pydotestpool')
            self.connid = id(mydb.conn)
            while hold:
                time.sleep(0.1)

    for i in range(10):
        t = mythread()
        threads.append(t)
        t.start()
    # we don't want any threads to terminate until
    # all threads have been initialized; otherwise,
    # some connections might get reused.
    ready = lambda t: hasattr(t, 'connid')
    while 1:
        if every(True, (ready(t) for t in threads)):
            break
        time.sleep(0.1)

    # let the threads die
    hold = False
    for t in threads:
        t.join()
    connids = [t.connid for t in threads]
    # assertion means: no connection has been handed out
    # to a plural number of simultaneously active threads
    assert len(connids) == len(set(connids))
def test_pool2():
    stuff=D._aliases['pydotest'].copy()
    D.initAlias('pydotestpool',
                stuff['driver'],
                stuff['connectArgs'],
                # keep_poolsize actually doesn't matter here
                D.ConnectionPool(max_poolsize=0, keep_poolsize=4),
                stuff['verbose'])
    hold=True
    threads=[]    
    class mythread(threading.Thread):
        def run(self):
            mydb=D.getConnection('pydotestpool')
            self.connid=id(mydb.conn)
            while hold:
                time.sleep(0.1)

    for i in range(10):
        t=mythread()
        threads.append(t)
        t.start()
    # we don't want any threads to terminate until
    # all threads have been initialized; otherwise,
    # some connections might get reused.
    ready=lambda t: hasattr(t, 'connid')
    while 1:
        if every(True, (ready(t) for t in threads)):
            break
        time.sleep(0.1)

    # let the threads die
    hold=False
    for t in threads:
        t.join()
    connids=[t.connid for t in threads]
    # assertion means: no connection has been handed out
    # to a plural number of simultaneously active threads
    assert len(connids)== len(set(connids))
Example #3
0
 def __get__(self, obj, type_):
     d = dict((x, obj[y]) for x, y in zip(self.that_side, self.this_side))
     if not every(None, d.itervalues()):
         return self.kls.getUnique(**d)
Example #4
0
 def __get__(self, obj, type_):
     d = dict((x, obj[y]) for x, y in zip(self.that_side, self.this_side))
     if not every(None, d.itervalues()):
         return self.kls.getUnique(**d)