Go to the latest version of this document.
search in docstrings

Search bar offers the following options:

- Term presence. The below example searches for documents that must contain “foo”, might contain “bar” and must not contain “baz”: `+foo bar -baz`
- Wildcards. The below example searches for documents with words beginning with “foo”: `foo*`
- Search in specific fields. The following search matches all objects in "twisted.mail" that matches “search”: `+qname:twisted.mail.* +search`

  Possible fields: 'name', 'qname' (fully qualified name), 'docstring', and 'kind'. Last two fields are only applicable if "search in docstrings" is enabled.

- Fuzzy matches. The following search matches all documents that have a word within 1 edit distance of “foo”: `foo~1`

Results provided by Lunr.js

# ``twisted`.`enterprise`.`adbapi`.`ConnectionPool``

class documentation

`class ConnectionPool: (source)`

Constructor: `ConnectionPool(dbapiName, *connargs, **connkw)`

View In Hierarchy

Represent a pool of connections to a DB-API 2.0 compliant database.

Method | `__getstate__` | Undocumented
Method | `__init__` | Create a new `ConnectionPool`.
Method | `__setstate__` | Undocumented
Method | `close` | Close all pool connections and shutdown the pool.
Method | `connect` | Return a database connection when one becomes available.
Method | `disconnect` | Disconnect a database connection associated with this pool.
Method | `finalClose` | This should only be called by the shutdown trigger.
Method | `runInteraction` | Interact with the database and return the result.
Method | `runOperation` | Execute an SQL query and return `None`.
Method | `runQuery` | Execute an SQL query and return the result.
Method | `runWithConnection` | Execute a function with a database connection and return the result.
Method | `start` | Start the connection pool.
Constant | `CP_ARGS` | Undocumented
Class Variable | `good_sql` | Undocumented
Class Variable | `name` | Undocumented
Class Variable | `noisy` | Undocumented
Class Variable | `openfun` | Undocumented
Class Variable | `reconnect` | Undocumented
Instance Variable | `__dict__` | Undocumented
Instance Variable | `connargs` | Undocumented
Instance Variable | `connectionFactory` | factory for connections, default to `Connection`.
Instance Variable | `connections` | Undocumented
Instance Variable | `connkw` | Undocumented
Instance Variable | `dbapi` | Undocumented
Instance Variable | `dbapiName` | Undocumented
Instance Variable | `max` | Undocumented
Instance Variable | `min` | Undocumented
Instance Variable | `running` | Undocumented
Instance Variable | `shutdownID` | `None` or a handle on the shutdown event trigger which will be used to stop the connection pool workers when the reactor stops.
Instance Variable | `startID` | Undocumented
Instance Variable | `threadID` | Undocumented
Instance Variable | `threadpool` | Undocumented
Instance Variable | `transactionFactory` | factory for transactions, default to `Transaction`.
Method | `_close` | Undocumented
Method | `_runInteraction` | Undocumented
Method | `_runOperation` | Undocumented
Method | `_runQuery` | Undocumented
Method | `_runWithConnection` | Undocumented
Method | `_start` | Undocumented
Instance Variable | `_reactor` | The reactor which will be used to schedule startup and shutdown events.

def __getstate__(self): (source)

Undocumented

def __init__(self, dbapiName, *connargs, **connkw): (source)

Create a new `ConnectionPool`.

Any positional or keyword arguments other than those documented here are passed to the DB-API object when connecting. Use these arguments to pass database names, usernames, passwords, etc.

Parameters
dbapiName | an import string to use to obtain a DB-API compatible module (e.g. `'pyPgSQL.PgSQL'`)
*connargs | Undocumented
cp_reactor:`IReactorCore` provider | use this reactor instead of the global reactor (added in Twisted 10.2).
cp_min | the minimum number of connections in pool (default 3)
cp_max | the maximum number of connections in pool (default 5)
cp_noisy | generate informational log messages during operation (default `False`)
cp_openfun | a callback invoked after every `connect()` on the underlying DB-API object. The callback is passed a new DB-API connection object. This callback can setup per-connection state such as charset, timezone, etc.
cp_reconnect | detect connections which have failed and reconnect (default `False`). Failed connections may result in `ConnectionLost` exceptions, which indicate the query may need to be re-sent.
cp_good_sql | an sql query which should always succeed and change no state (default `'select 1'`)

def __setstate__(self, state): (source)

Undocumented

def close(self): (source)

Close all pool connections and shutdown the pool.

def connect(self): (source)

Return a database connection when one becomes available.

This method blocks and should be run in a thread from the internal threadpool. Don't call this method directly from non-threaded code. Using this method outside the external threadpool may exceed the maximum number of connections in the pool.

Returns
a database connection from the pool.

def disconnect(self, conn): (source)

Disconnect a database connection associated with this pool.

Note: This function should only be used by the same thread which called `ConnectionPool.connect`. As with `connect`, this function is not used in normal non-threaded Twisted code.

def finalClose(self): (source)

This should only be called by the shutdown trigger.

def runInteraction(self, interaction, *args, **kw): (source)

Interact with the database and return the result.

The 'interaction' is a callable object which will be executed in a thread using a pooled connection. It will be passed an `Transaction` object as an argument (whose interface is identical to that of the database cursor for your DB-API module of choice), and its results will be returned as a `Deferred`. If running the method raises an exception, the transaction will be rolled back. If the method returns a value, the transaction will be committed.

NOTE that the function you pass is *not* run in the main thread: you may have to worry about thread-safety in the function you pass to this if it tries to use non-local objects.

Parameters
interaction | a callable object whose first argument is an `adbapi.Transaction`.
*args | additional positional arguments to be passed to interaction
**kw | keyword arguments to be passed to interaction
Returns
a Deferred which will fire the return value of `interaction(Transaction(...), *args, **kw)`, or a `twisted.python.failure.Failure`.

def runOperation(self, *args, **kw): (source)

Execute an SQL query and return `None`.

A DB-API cursor which will be invoked with `cursor.execute(*args, **kw)`. The exact nature of the arguments will depend on the specific flavor of DB-API being used, but the first argument in `*args` will be an SQL statement. This method will not attempt to fetch any results from the query and is thus suitable for `INSERT`, `DELETE`, and other SQL statements which do not return values. If the 'execute' method raises an exception, the transaction will be rolled back and a `Failure` returned.

The `*args` and `*kw` arguments will be passed to the DB-API cursor's 'execute' method.

Returns
a `Deferred` which will fire with `None` or a `twisted.python.failure.Failure`.

def runQuery(self, *args, **kw): (source)

Execute an SQL query and return the result.

A DB-API cursor which will be invoked with `cursor.execute(*args, **kw)`. The exact nature of the arguments will depend on the specific flavor of DB-API being used, but the first argument in `*args` be an SQL statement. The result of a subsequent `cursor.fetchall()` will be fired to the `Deferred` which is returned. If either the 'execute' or 'fetchall' methods raise an exception, the transaction will be rolled back and a `twisted.python.failure.Failure` returned.

The `*args` and `**kw` arguments will be passed to the DB-API cursor's 'execute' method.

Returns
a `Deferred` which will fire the return value of a DB-API cursor's 'fetchall' method, or a `twisted.python.failure.Failure`.

def runWithConnection(self, func, *args, **kw): (source)

Execute a function with a database connection and return the result.

Parameters

func

A callable object of one argument which will be executed in a thread with a connection from the pool. It will be passed as its first argument a `Connection` instance (whose interface is mostly identical to that of a connection object for your DB-API module of choice), and its results will be returned as a `Deferred`. If the method raises an exception the transaction will be rolled back. Otherwise, the transaction will be committed. Note that this function is not run in the main thread: it must be threadsafe.

*args | positional arguments to be passed to func
**kw | keyword arguments to be passed to func
Returns
a `Deferred` which will fire the return value of `func(Transaction(...), *args, **kw)`, or a `twisted.python.failure.Failure`.

def start(self): (source)

Start the connection pool.

If you are using the reactor normally, this function does *not* need to be called.

CP_ARGS = (source)

Undocumented

Value

    """min max name noisy openfun reconnect good_sql""".split()

good_sql: `str` = (source)

Undocumented

name = (source)

Undocumented

noisy: `bool` = (source)

Undocumented

openfun = (source)

Undocumented

reconnect: `bool` = (source)

Undocumented

__dict__ = (source)

Undocumented

connargs = (source)

Undocumented

connectionFactory: any callable. = (source)

factory for connections, default to `Connection`.

connections: `dict` = (source)

Undocumented

connkw = (source)

Undocumented

dbapi = (source)

Undocumented

dbapiName = (source)

Undocumented

max = (source)

Undocumented

min = (source)

Undocumented

running: `bool` = (source)

Undocumented

shutdownID = (source)

`None` or a handle on the shutdown event trigger which will be used to stop the connection pool workers when the reactor stops.

startID = (source)

Undocumented

threadID = (source)

Undocumented

threadpool = (source)

Undocumented

transactionFactory: any callable = (source)

factory for transactions, default to `Transaction`.

def _close(self, conn): (source)

Undocumented

def _runInteraction(self, interaction, *args, **kw): (source)

Undocumented

def _runOperation(self, trans, *args, **kw): (source)

Undocumented

def _runQuery(self, trans, *args, **kw): (source)

Undocumented

def _runWithConnection(self, func, *args, **kw): (source)

Undocumented

def _start(self): (source)

Undocumented

_reactor: `IReactorCore` provider = (source)

The reactor which will be used to schedule startup and shutdown events.