~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/pool.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2013-10-28 22:29:40 UTC
  • mto: (1.6.9)
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: package-import@ubuntu.com-20131028222940-t6h277tm5kaiepk4
Tags: upstream-0.8.3
Import upstream version 0.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
129
129
          :meth:`unique_connection` method is provided to bypass the
130
130
          threadlocal behavior installed into :meth:`connect`.
131
131
 
132
 
        :param reset_on_return: If true, reset the database state of
133
 
          connections returned to the pool.  This is typically a
134
 
          ROLLBACK to release locks and transaction resources.
135
 
          Disable at your own peril.  Defaults to True.
 
132
        :param reset_on_return: Configures the action to take
 
133
          on connections as they are returned to the pool.
 
134
          See the argument description in :class:`.QueuePool` for
 
135
          more detail.
136
136
 
137
137
        :param events: a list of 2-tuples, each of the form
138
138
         ``(callable, target)`` which will be passed to event.listen()
359
359
                self.__pool.dispatch.connect(self.connection, self)
360
360
        return self.connection
361
361
 
 
362
    def checkin(self):
 
363
        self.fairy = None
 
364
        connection = self.connection
 
365
        pool = self.__pool
 
366
        if self.finalize_callback:
 
367
            self.finalize_callback(connection)
 
368
            del self.finalize_callback
 
369
        if pool.dispatch.checkin:
 
370
            pool.dispatch.checkin(connection, self)
 
371
        pool._return_conn(self)
 
372
 
362
373
    def __close(self):
363
374
        self.__pool._close_connection(self.connection)
364
375
 
380
391
                connection_record.fairy is not ref:
381
392
        return
382
393
 
 
394
    if connection_record and echo:
 
395
        pool.logger.debug("Connection %r being returned to pool",
 
396
                                connection)
 
397
 
383
398
    if connection is not None:
384
399
        try:
385
400
            if pool.dispatch.reset:
397
412
            if isinstance(e, (SystemExit, KeyboardInterrupt)):
398
413
                raise
399
414
 
400
 
    if connection_record is not None:
401
 
        connection_record.fairy = None
402
 
        if echo:
403
 
            pool.logger.debug("Connection %r being returned to pool",
404
 
                                    connection)
405
 
        if connection_record.finalize_callback:
406
 
            connection_record.finalize_callback(connection)
407
 
            del connection_record.finalize_callback
408
 
        if pool.dispatch.checkin:
409
 
            pool.dispatch.checkin(connection, connection_record)
410
 
        pool._return_conn(connection_record)
 
415
    if connection_record:
 
416
        connection_record.checkin()
411
417
 
412
418
 
413
419
_refs = set()
423
429
        self._echo = _echo = pool._should_log_debug()
424
430
        try:
425
431
            rec = self._connection_record = pool._do_get()
426
 
            conn = self.connection = self._connection_record.get_connection()
 
432
            try:
 
433
                conn = self.connection = self._connection_record.get_connection()
 
434
            except:
 
435
                self._connection_record.checkin()
 
436
                raise
427
437
            rec.fairy = weakref.ref(
428
438
                            self,
429
439
                            lambda ref: _finalize_fairy and \