Asynchronous database transactions via SQLAlchemy and Twisted. You will surely have a subclass of AccessBroker.

Function transaction Everything making up a transaction, and everything run in the thread, is contained within this little function, including of course a call to func.
Function nextFromRP Transaction magic.
Function isNested Transaction magic.
Function transact Transaction decorator.
Function wait Decorator to wait for any Deferred that has been returned by a method of AccessBroker to fire before proceeding with the shutdown method of AccessBroker.
Class AccessBroker I manage asynchronous access to a database.
def transaction(self, func, *t_args, **t_kw):

Everything making up a transaction, and everything run in the thread, is contained within this little function, including of course a call to func.

def nextFromRP(rp, N=1):

Transaction magic.

def isNested(self):

Transaction magic.

def transact(f):

Transaction decorator.

Use this function as a decorator to wrap the supplied method f of AccessBroker in a transaction that runs f(*args, **kw) in its own transaction.

Immediately returns a Deferred that will eventually have its callback called with the result of the transaction. Inspired by and largely copied from Valentino Volonghi's makeTransactWith code.

You can add the following keyword options to your function call:

ParametersnicenessScheduling niceness, an integer between -20 and 20, with lower numbers having higher scheduling priority as in UNIX nice and renice.
doNextSet True to assign highest possible priority, even higher than with niceness = -20.
doLastSet True to assign lower possible priority, even lower than with niceness = 20.
consumerSet this to a consumer object (must implement the twisted.interfaces.IConsumer interface) and the SA.ResultProxy will write its rows to it in Twisted fashion. The returned Deferred will fire when all rows have been written.
rawSet True to have the transaction result returned in its original form even if it's a RowProxy or other iterator.
def wait(f):

Decorator to wait for any Deferred that has been returned by a method of AccessBroker to fire before proceeding with the shutdown method of AccessBroker.

Sometimes calls to methods you define to an AccessBroker subclass will still be pending when you call for a shutdown. If those pending calls rely on the task queue to finish, you can wait for them before the AccessBroker.shutdown method proceeds by decorating the method with this function.

API Documentation for sAsync, generated by pydoctor at 2021-09-18 08:41:22.