[Twisted-Python] A Python metaclass for Twisted allowing __init__ to return a Deferred

Esteve Fernandez esteve at sindominio.net
Mon Nov 3 08:53:24 EST 2008

On Monday 03 November 2008 14:11:05 Terry Jones wrote:
> >>>>> "Esteve" == Esteve Fernandez <esteve at sindominio.net> writes:
> Esteve> I'm going to jump in. How about this:
> That's nice. But you've coupled the args to aFuncReturningADeferred and
> what it's Deferred ends up returning to the args for __init__ of the class.

Yep, that's what I meant. I wanted to show how to pass an argument to Foo, 
which will be used to call a function (that may take a considerable amount of 
time) and whose return value will be stored in a Foo instance.

Following your example at http://bit.ly/1whZUK, you may pass the database name 
as an argument to DatabaseClass, call prepareConnection (a function that 
returns a Deferred) in the __new__ method to create the necessary tables and 
pass a ConnectionPool in the Deferred chain, so it can end up being stored as 
an instance variable of a DatabaseClass object.


More information about the Twisted-Python mailing list