[Twisted-Python] Confused about threads

Simon Pickles sipickles at hotmail.com
Mon Nov 19 08:10:38 EST 2007

I certainly don't use the twisted framework for my whole application, 
just the  networking.

For instance, I have an app which is a server to many clients, but also 
a client itself to another server, in order to pass system information. 
Therefore my code looks something like this pseudocode:

    #main thread
    reactor.listenTCP(serverPort, myFactory(max_clients = 0))
    reactor.connectTCP(otherServerHost, otherServerPort, myClientFactory())
myProcessingThread is a class inheriting from Threading, and processes 
messages stored in queues by the Twisted thread, with the correct 
locking of course (Queues).

I don't doubt that there are many ways to use twisted more. This works 
for me, and allows me to get on with the meat of the project.



Mark L 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.
> 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.
> Thanks,
> Mark
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

More information about the Twisted-Python mailing list