Habit, mostly.  I think it's a good habit, though.  The reason is that I
wanted to make sure the __init__ code completed before the connectTCP was
called.  In this case, it doesn't matter, but if I had a number of things I
wanted to do in __init__, it might matter.  Consider:

class MyClientProtocol(Protocol):
      def connectionMade(self):
        self.factory.numConnections += 1

class MyClientFactory(Factory):
      def __init__(self):
        reactor.connectTCP(host, port, self)
  self.numConnections = 0

'course, I'm sure you'd put reactor.connectTCP *after* the numConnections
initializer, but using callWhenRunning ensures that the order doesn't
matter, so it's one less thing you have to worry about :-)

Jason

On Wed, Jan 12, 2011 at 4:49 AM, <benjamin.bertr...@lfv.se> wrote:

> One small question about the following code:
> Why did you use reactor.callWhenRunning in the __init__ method?
> Why not calling directly reactor.connectTCP?
>
> Cheers,
>
> Benjamin
>
>
-- 
Jason Rennie
Research Scientist, ITA Software
617-714-2645
http://www.itasoftware.com/
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to