[Twisted-Python] Basic factory question

Coming from C++ to python/twisted. Looking at samples, created a simple server and want to create a tester file that will create many clients to connect to and exercise my server. All very nice and easy and like this a lot so far. The one thing that looks strange to me is that the samples instantiate a ClientFactory to then connect to the server via reactor.connectTCP(). I copied this pattern, worried that a factory would be created for every one of my clients, and this is indeed what happened. Isn't the point of a factory to generate all of the clients? I'd like to keep some aggregate info in 1 factory, and have the factory contain the dbpools, etc.. How to do this?

On Mon, 13 Apr 2009 11:25:12 -0700, Ted Pederson <ted.pederson@gmail.com> wrote:
Coming from C++ to python/twisted. Looking at samples, created a simple server and want to create a tester file that will create many clients to connect to and exercise my server. All very nice and easy and like this a lot so far.
The one thing that looks strange to me is that the samples instantiate a ClientFactory to then connect to the server via reactor.connectTCP().
I copied this pattern, worried that a factory would be created for every one of my clients, and this is indeed what happened. Isn't the point of a factory to generate all of the clients? I'd like to keep some aggregate info in 1 factory, and have the factory contain the dbpools, etc.. How to do this?
You can pass a single ClientFactory instance to connectTCP multiple times, if that's what you want to do. If the factory is where you keep various other resources for the client connections to use, then this makes perfect sense. Jean-Paul
participants (2)
-
Jean-Paul Calderone
-
Ted Pederson