Changeset 73
- Timestamp:
- 08/08/07 16:33:30 (1 year ago)
- Files:
-
- projects/sAsync/branches/multithread (copied) (copied from projects/sAsync/trunk)
- projects/sAsync/branches/multithread/sasync/database.py (modified) (6 diffs)
- projects/sAsync/branches/multithread/sasync/transactions.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
projects/sAsync/branches/multithread/sasync/database.py
r57 r73 29 29 from twisted.python import failure 30 30 import sqlalchemy as SA 31 from asynqueue import ThreadQueue32 31 33 32 import misc 33 from transactions import TransactionQueue 34 34 35 35 … … 196 196 U{http://www.sqlalchemy.org/docs/dbengine.myt}. 197 197 198 @cvar numThreads: An integer specifying the number of threads to use for 199 transactions (default 1) 200 198 201 @ivar dt: A property-generated reference to a deferred tracker that you can 199 202 use to wait for database writes. See L{misc.DeferredTracker}. … … 206 209 207 210 """ 211 numThreads = 1 208 212 globalParams = ('', {}) 209 213 queues = {} … … 242 246 """ 243 247 Returns a threaded task queue that is dedicated to my database 244 connection. Creates the queue if the first time the property is 245 accessed. 248 connection. Creates the queue the first time the property is accessed. 246 249 """ 247 250 def newQueue(): 248 queue = T hreadQueue(1)251 queue = TransactionQueue(self.numThreads) 249 252 self.running = True 250 253 self.queues[key] = queue … … 269 272 """) 270 273 271 def connect(self, forceNew=False): 272 """ 273 Generates and returns a singleton connection object. 274 def connect(self, threadID, forceNew=False): 275 """ 276 Generates and returns a connection object that serves all transations 277 within a given thread. 278 279 Runs in a transaction thread. 274 280 """ 275 281 def getEngine(): 276 if hasattr(self, '_dEngine'):277 d = defer.Deferred()278 d.addCallback(lambda _: getConnection())279 self._dEngine.chainDeferred(d)280 else:281 d = self._dEngine = \282 self.q.call(createEngine, doNext=True)283 d.addCallback(gotEngine)284 return d285 286 def createEngine():287 282 url, kw = self.engineParams 288 283 kw['strategy'] = 'threadlocal' 289 return SA.create_engine(url, **kw) 290 291 def gotEngine(engine): 292 del self._dEngine 293 self._engine = engine 294 return getConnection() 284 self._engine = SA.create_engine(url, **kw) 285 self.connections = {} 295 286 296 287 def getConnection(): … … 313 304 314 305 # After all these function definitions, the method begins here 315 if hasattr(self, '_engine'): 316 return getConnection() 317 else: 318 return getEngine() 306 if not hasattr(self, '_engine'): 307 getEngine() 308 return getConnection() 319 309 320 310 def _sessionClose(self):
