[Twisted-Python] design of twisted application

Michael Thompson michaelnt at gmail.com
Wed Feb 2 03:05:08 EST 2011


On 2 February 2011 07:15, Kurt Spindler <kespindler at gmail.com> wrote:
> Hey,
> I am trying to design a twisted application, (I'm pretty new to twisted and
> networking in general) and I feel like I'm not approaching it quite the
> right way and would appreciate your feedback. First part, is that I am
> trying to couple twisted with an existing graphics-type application, that
> already has it's own main loop, etc. Meaning, I need to be running other
> python code while I have the reactor running. Is the solution threading?

Hopefully there is already a twisted reactor for your graphics
library, what are you using?

>
>
>   f = MyFactory()
>
>   reactor.connectTCP("localhost",22223,f)
>
>   t = threading.Thread(target=reactor.run)
>
>   t.run()
>
>   runOtherCodeConcurrently()
>
> Is there a better solution? Second question is that, in that other bunch of
> code, I need to be able to write things to the socket. How can I access the
> instance of my protocol subclass that is used by the factory, so I can make
> protocolInstance.transport.write type calls? Or am I thinking about this is
> a completely wrong way?

You should be able to do this on the Factory that created the protocol instance.

Michael



More information about the Twisted-Python mailing list