diff -r 8b493ab9c74f -r ea437d1e7b65 iro/model/utils.py --- a/iro/model/utils.py Thu Jan 26 01:20:03 2012 +0100 +++ b/iro/model/utils.py Thu Jan 26 01:21:32 2012 +0100 @@ -1,19 +1,26 @@ from sqlalchemy.orm import sessionmaker -from twisted.internet import reactor from twisted.internet import threads from twisted.python.threadpool import ThreadPool POOL_SIZE=5 #how many threads should the db connector pool should have -dbpool = ThreadPool(minthreads=1, maxthreads=POOL_SIZE, name='database') -dbpool.start() -reactor.addSystemEventTrigger('before', 'shutdown', dbpool.stop) +class Data: + def __init__(self): + self.pool = ThreadPool(minthreads=1, maxthreads=POOL_SIZE, name='database') + self.reactor = None + +d = Data() + +def startPool(reactor): + d.pool.start() + d.reactor = reactor + d.reactor.addSystemEventTrigger('before', 'shutdown', d.pool.stop) def run_in_db_thread(f): """Decorator to run DB queries in Twisted's thread pool""" def wrapper(*args, **kwargs): - return threads.deferToThreadPool(reactor, dbpool,f, *args, **kwargs) + return threads.deferToThreadPool(d.reactor, d.pool, f, *args, **kwargs) return wrapper