[Twisted-Python] Factory.startFactory being called twice.
Hi all, I recently upgraded to 0.14.0, but I'm still seeing Factory.startFactory() being called twice when I start my server. If I start my server with the following code (adapted from simpleserv.py): app = Application('spam') app.listenTCP(1234,MyFactory()) app.run(save=0) Then by using traceback.format_stack() in MyFactory.startFactory I can see that it gets called twice, here: app.run(save=0) File "F:\Python22\Lib\site-packages\twisted\internet\app.py", line 350, in run port.startListening() File "F:\Python22\Lib\site-packages\twisted\internet\tcp.py", line 395, in startListening self.factory.startFactory() and here: app.run(save=0) File "F:\Python22\Lib\site-packages\twisted\internet\app.py", line 357, in run port.factory.startFactory() I'm currently using if not hasattr(self, 'once'): self.once = 1 # ... To workaround it, but it'd be nice to not need to do this. The docs suggest that it will get called twice, "both after an application has been unserialized and before all the ports begin accepting connections." Which is fine, except that I'm not unserialising... It's a minor glitch in an otherwise beautiful system :) -Andrew.
andrew-twisted@puzzling.org wrote:
I recently upgraded to 0.14.0, but I'm still seeing Factory.startFactory() being called twice when I start my server.
OK, I fixed it in CVS. I tested, and now it only runs once, both when loading from a .tap and when being run directly. Here's the patch: Index: twisted/internet/tcp.py =================================================================== RCS file: /cvs/Twisted/twisted/internet/tcp.py,v retrieving revision 1.42 diff -c -r1.42 tcp.py *** twisted/internet/tcp.py 29 Jan 2002 17:25:25 -0000 1.42 --- twisted/internet/tcp.py 30 Jan 2002 16:13:11 -0000 *************** *** 392,398 **** self.fileno = self.socket.fileno self.numberAccepts = 100 self.startReading() - self.factory.startFactory() def approveConnection(self, sock, addr): """Check that this is a connection we are willing to accept. --- 392,397 ----
participants (2)
-
andrew-twistedï¼ puzzling.org
-
Itamar Shtull-Trauring