[Twisted-Python] Confused about threads

Jean-Paul Calderone exarkun at divmod.com
Mon Nov 19 07:48:25 EST 2007


On Mon, 19 Nov 2007 19:44:08 +1100, Mark L <mark.lachesis at gmail.com> wrote:
>Hi,
>
>I'm new to twisted, and have read a few pages, but things are going
>over my head and I'm not finding the answer I need.
>
>What I want to do is create a class in my python application which
>manages network activity and starts the reactor.  I want to run that
>class as a thread.
>
>I've done all of this, except when I get to reactor.run().  Then it
>says that signal must be started in main.  If I move the reactor.run()
>into main then it starts up fine - but it doesn't run in a separate
>thread.  I want the network running in the background in a separate
>thread so I can manage other server tasks distinctly.

"so I can manage other server tasks distinctly" doesn't make a lot of
sense as a motivation here.  Maybe that's because you don't have the
right idea about how to write servers with Twisted yet, or maybe it's
just because you haven't explained your requirements sufficiently.

>
>I realise this is probably a critical misunderstanding on my part of
>how twisted is meant to be used - so I'd appreciate any clarifications
>on this point that I wasn't able to find in the documentation.  Which,
>again, is probably just a critical failure of mine to find.

It's possible to run the reactor in a different thread, but the reason
to do so is usually that you already have a second mainloop which you
can't easily integrate with the reactor's mainloop.  In other cases, you
can typically accomplish whatever you need without starting any threads.

Jean-Paul




More information about the Twisted-Python mailing list