[Twisted-Python] Avoid circullair dependencies.

Some of my logic need protocol to be imoported to be able to send data back. So when I start app protocol imports my logic (where all data is processed) and my logic imports protocol. Right now I simply pass protocol object as argument to constructors, but it seems to be not the best way from my point of view. How to solve this problem?

Sounds like you could use a lazy import. I do something similar to this in my factory: # protocol.py class MyProtocol(XmlStream): .... class MyFactory: def buildProtocol(self, addr): myProtocol = MyProtocol() # heres the lazy import from othermodule import SomeKlass SomeKlass(myProtocol) My `othermodule' imports some constants from `protocol' (module defined above). So, to kill the circular references, I do a lazy import in MyFactory. HTH! jw On 7/1/07, Ivanov Maxim <redbaron@hitv.ru> wrote:
-- "Government does not solve problems; it subsidizes them." Ronald Reagan

Sounds like you could use a lazy import. I do something similar to this in my factory: # protocol.py class MyProtocol(XmlStream): .... class MyFactory: def buildProtocol(self, addr): myProtocol = MyProtocol() # heres the lazy import from othermodule import SomeKlass SomeKlass(myProtocol) My `othermodule' imports some constants from `protocol' (module defined above). So, to kill the circular references, I do a lazy import in MyFactory. HTH! jw On 7/1/07, Ivanov Maxim <redbaron@hitv.ru> wrote:
-- "Government does not solve problems; it subsidizes them." Ronald Reagan
participants (2)
-
Ivanov Maxim
-
Jaime Wyant