[Twisted-Python] Basic question about the architecture of twisted.internet

Jean-Paul Calderone exarkun at divmod.com
Mon Oct 13 10:53:27 EDT 2008

On Mon, 13 Oct 2008 16:49:03 +0200, Peter Jacobi <pjacobi.de at googlemail.com> wrote:
>Dear All,
>I've just started diving into Twisted, read the docs, run the samples, wrote
>some tests, but:
>I'm rather clueless about some architectural decisions in Twisted Core, and
>perhaps somebody can clarify whether these are just hictorical accidents or
>serve a purpose I didn't get yet.
>Specifically I don't understand why the Factory classes in internet/protocols.py
>rely on class variables instead of instance variables for, most
>importantly "protocol",
>but also for "noisy" and "numPorts"?
>Won't this introduce an unwanted coupling between different instances
>of Factory,
>and effectively make the creation of more than instance of any Factory-derived
>class pointless (or even incorrect). Sort of a singleton pattern relying on the
>trust principle?

Factories don't "rely" on class *attributes*.  Attribute lookup on instances
in Python first checks the instance dictionary then the class dictionary.  If
an attribute is found on the instance, then the class is ignored.  So when
you are setting attributes such as `noisy´ or `protocol´, if you want the
change to only modify the behavior of one instance, then set the attribute
on an instance, not on the class.


More information about the Twisted-Python mailing list