[Twisted-Python] Issue with factories
![](https://secure.gravatar.com/avatar/433365de0f787faa3ed3e6dd1da5884f.jpg?s=120&d=mm&r=g)
If you do reactor.listenTCP on a factory, startFactory and stopFactory are never called. I therefore suggest that we add methods doStart and doStop to protocol.Factory, like so, and have them called in listenTCP/UDP/SSL, and remove calls to start/stopFactory from app.Appliecation: class Factory: running = 0 def doStart(self): if not self.running: self.running = 1 self.startFactory() def doStop(self): if self.running: self.running = 0 self.stopFactory() This ensures the start/stopFactory methods will only be called once, even if the factory is added to multiple Ports, and makes sure that they get called even if the factory is added to the reactor directly.
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
From: Itamar Shtull-Trauring <twisted@itamarst.org> Date: Tue, 28 May 2002 19:18:45 +0300
If you do reactor.listenTCP on a factory, startFactory and stopFactory are never called. I therefore suggest that we add methods doStart and doStop to protocol.Factory, like so, and have them called in listenTCP/UDP/SSL, and remove calls to start/stopFactory from app.Appliecation:
Thanks. I knew this was a problem but didn't know how to confront it; this looks like a logical encapsulation, parallel to doRead/doWrite... perhaps doStart and doStop could also take information about the port being listened on as an argument. (doListen/doUnlisten maybe?) -- | <`'> | Glyph Lefkowitz: Travelling Sorcerer | | < _/ > | Lead Developer, the Twisted project | | < ___/ > | http://www.twistedmatrix.com |
![](https://secure.gravatar.com/avatar/269141092655512a3b5a234bf25d17b2.jpg?s=120&d=mm&r=g)
Here is a diagram "reverse-engineered" from the Python code using the Object Domain UML tool (with some manual tweaking to organize it more compactly). This is from the CVS twisted I checked out on 5/24 (haven't updated since then). If you think it's useful, I could send more as I generate them, and they could be included with the Twisted docs if you want. Of course, there is no substitute for reading the code, but might be a good "quick reference". I think there is a new release of twisted coming soon, right? If so, I'll wait for that .... -- Steve. Stephen C. Waterbury http://misspiggy.gsfc.nasa.gov/people/waterbug.html "An idiot with a computer is a faster, better idiot." - Rick Julius
![](https://secure.gravatar.com/avatar/433365de0f787faa3ed3e6dd1da5884f.jpg?s=120&d=mm&r=g)
Itamar Shtull-Trauring wrote:
If you do reactor.listenTCP on a factory, startFactory and stopFactory are never called. I therefore suggest that we add methods doStart and doStop to protocol.Factory, like so, and have them called in listenTCP/UDP/SSL, and remove calls to start/stopFactory from app.Appliecation:
OK, done, basically identically to the pseudocode listed in previous email, slighly improved - I will check in after 0.18 is released.
participants (3)
-
Glyph Lefkowitz
-
Itamar Shtull-Trauring
-
Steve Waterbury