[Twisted-Python] "Old style" classes in Twisted and inheritance

Andy Fundinger Andy at NewWorldElectric.com
Tue Nov 13 07:34:08 MST 2007


I ran into this too, but have had no trouble 'converting' to new style
classes by just adding "object" to the superclass list.  Anyone have reasons
why we can't do that?

-Andy Fundinger

On Nov 13, 2007 9:07 AM, Atilla <theatilla at gmail.com> wrote:

> I hope this is the correct place for this question.
>
> I was trying to create a little customized task that sends a (ping)
> message to the clients every X seconds. Because I needed some extra
> bookkeeping, I implemented it as a class instance with a __call__
> method, that is passed to the LoopingCall.
>
> However, I also wanted to automatically start the task on init, so I
> thought - it makes a lot of sense to simply Inherit it, call its
> constructor and pass self as the parameter. It was then I realized
> that the classes in twisted are old-style, when my super() call didn't
> work.
>
> Is there any practicular reason for that? Am I wrong to try inherit
> the Looping Call ? Basically my code looks like :
>
> class SillyPinger(object):
>        def __init__(self, factory):
>            self.factory = factory
>            self.pingTargets = {}
>
>            pingTask = task.LoopingCall(self)
>            pingTask.start(5.0)
>
>        def __call__(self):
>            # do stuff
>            pass
>
>
> while I'd like to be doing:
>
> class SillyPinger(task.LoopingCall):
>        def __init__(self, factory):
>            super(SillyPinger, self).__init__(self)
>
>            self.factory = factory
>            self.pingTargets = {}
>
>            self.start(5.0) # get value from .ini here
>
>
> Should I just switch to calling the LoopingCall constructor in the old
> way? I'm not sure I'd like to do that, even if only for consistency
> reasons.
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>



-- 
Blog:  http://channel3b.wordpress.com
Second Life Name:  Ciemaar Flintoff

I am a sig Virus. Please put me in your sig so that I can continue to
replicate.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20071113/8dadfb55/attachment.html>


More information about the Twisted-Python mailing list