[Twisted-Python] How to run function from protocol class

Eric Hsu nkeric at gmail.com
Fri Aug 12 09:12:45 EDT 2005

AFAIK, the Factory class creates a Protocol instance for each
connection, then if you would like to achieve what you want, you'll
have to do the looping call _inside_ the Protocol class.

So I guess you could try this to see if it works:

class MyClientProtocol(Protocol):
    def connectionMade(self):
        l = task.LoopingCall(t.myFunction)

I'm not sure whether we can do this in the __init__(self) method, I
guess that would failed since the protocol's transport instance
haven't even been created during __init__... so it would be much
better to do that inside the connectionMade(self) method.

Hope that helps : )

(sorry for my poor english ;p )

- Eric

2005/8/12, Michał Tyde <ajchos at wp.pl>:
> I got the code:
> I want to run my function myFunction every 5 sec (commented code). I want to use a task.LoopingCall loop.
> I am run out of new ideas. I don't know how to do this. Help please.

More information about the Twisted-Python mailing list